Android - Activity and Application


#1

I’m trying to integrate ACRA lib into an Extension but I’ve found a big issuer for my poor Android knowledge.
ACRA need to integrate some code into an extended Application class. Looking at template used by lime to generate android apks, i’ve found no trace about a “MainApplication” or so on.

Is there a way to try to add or use an extended Application class to lime or to reach “MainApplication” from main Activity?

Thanks, David.


#2

Oh, just read that you want to make an Extension.

Probably there is no way to add custom application class from extension (moreover I believe that it is bad idea to modify application class from extension).


Previous answer:

OpenFL / Lime didn’t use custom application class. You should create it by yourself.

  1. Override android template, to do it put
<template path="templates" />

inside project.xml

  1. inside templates folder create following folders: android/template/app/src/main/java/org/haxe/lime

  2. copy AndroidManifest.xml from Lime (https://github.com/openfl/lime/blob/develop/templates/android/template/app/src/main/AndroidManifest.xml) to templates/android/template/app/src/main

  3. create MainApplication.java inside templates/android/template/app/src/main/java/org/haxe/lime/

  4. Project structure should be like that:

root_of_project/
|- ...
|- templates/
|  |- android/
|     |- template/
|        |- app/
|           |- src/
|              |- main/
|                 |- java/
|                 |  |- org/
|                 |  |  |- haxe/
|                 |  |  |  |- lime/
|                 |  |  |  |  |- MainApplication.java
|                 |- AndroidManifest.xml
|- project.xml
  1. in AndroidManifest.xml find <application ...> tag, and add android:name=".MainApplication" somewhere:
<application android:name=".MainApplication" ...>
  1. open MainApplication.java, and put following inside:
package org.haxe.lime;

import android.app.Application;
import android.content.Context;
import org.acra.*;
import org.acra.annotation.*;

@ReportsCrashes(formUri = "http://www.backendofyourchoice.com/reportpath")
public class MainApplication extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        ACRA.init(this);
    }
}

P. S. I didn’t test it, but I believe that it should work.


Extension for Deep Links on Android (Solved with example)
#3

Really thanks about your kindly and complete response. I’m going to try to integrate it into my projects.
David.


#4

I updated answer, TL;DR - probably it is impossible if you want to make an extension.

But if you just want to integrate ACRA into application, my answer should help :slight_smile:


#5

It’s a chance. I’m not sure ACRA can really help with NDK applications buy I’m going to try in next days. But your response can be really useful to expand openfl/lime limits with Android.

Thanks again, David.


#6

I recently implemented ACRA myself, and I used pretty much the same implementation Restorer suggested. Sadly, ACRA doesn’t seem to report C++ crashes, so I’m not expecting to get a whole lot out of it.


#7

Thanks a lot @player_03 I’m going to waste my time to try to produce a crashlytics working on Android side. Main issue in this task is the absolute strange and non-comprensible documentation and a strange way to share knowledge, almost for an old programmer :smiley:

David.