I'm trying to create a library to use ACRA in B4A.
ACRA is an Application Crash Report for Android tool, when your app crashes ACRA can send a crash report to various destinations.
It can send the report to your Google Docs, to a custom script on your web server or it can email the report to you.
I've successfully used it in a native android java app and thought it'd make a good addition to the B4A libraries so...
I started with a class that extends the Android Application class:
(The ACRA source code is part of the B4A library project in Eclipse - no need for a jar file and the DependsOn annotation).
Updated my manifest:
(Even though the INTERNET permission is set in the library i noticed that it was not added to the manifest - probably because the library is not an Activity object?)
And created a simple B4A project to test it:
The project compiles and runs, the log shows:
So the Application sub class has successfully been created.
A click on the ExceptionsButton raises an exception:
But no crash report is sent to my Google Docs account.
With my java android project the same code would have send a crash report to my Google Docs account and i'd have received an email notification.
I tried different methods to cause the B4A project to crash:
An attempt to divide by zero failed to raise an exception, instead the division produced the result Infinity.
An infinite do while loop eventually force closed the app but again no crash report was sent.
I'm wondering if B4A has it's own exception handling code which sits on top of the native android exception handling and this B4A code is intercepting the exceptions which ACRA would otherwise report?
Martin.
ACRA is an Application Crash Report for Android tool, when your app crashes ACRA can send a crash report to various destinations.
It can send the report to your Google Docs, to a custom script on your web server or it can email the report to you.
I've successfully used it in a native android java app and thought it'd make a good addition to the B4A libraries so...
I started with a class that extends the Android Application class:
B4X:
package uk.co.martinpearman.b4a.acra4b4a;
import org.acra.ACRA;
import org.acra.annotation.ReportsCrashes;
import android.app.Application;
import android.util.Log;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@Author("Martin Pearman")
@ReportsCrashes(formKey="dHZVX1F4OW9mWjlTSmtSM0VvaFFuN1E6MQ")
@Permissions(values = {"android.permission.INTERNET"})
@ShortName("ACRA4B4A")
@Version(1.00f)
public class ACRAApplication extends Application {
@Override
public void onCreate() {
ACRA.init(this);
super.onCreate();
Log.d("B4A", "ACRAApplication onCreate");
}
}
(The ACRA source code is part of the B4A library project in Eclipse - no need for a jar file and the DependsOn annotation).
Updated my manifest:
B4X:
SetApplicationAttribute(android:name, "uk.co.martinpearman.b4a.acra4b4a.ACRAApplication")
AddPermission(android.permission.INTERNET)
(Even though the INTERNET permission is set in the library i noticed that it was not added to the manifest - probably because the library is not an Activity object?)
And created a simple B4A project to test it:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ExceptionButton As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ExceptionButton_Click
Activity.AddView(ExceptionButton, 0, 0, 100%x, 60dip)
End Sub
The project compiles and runs, the log shows:
Retrieve application default SharedPreferences.
Set OnSharedPreferenceChangeListener.
ACRA is enabled for uk.co.martinpearman.b4a.acrademo, intializing...
Looking for error files in /data/data/uk.co.martinpearman.b4a.acrademo/files
ACRAApplication onCreate
So the Application sub class has successfully been created.
A click on the ExceptionsButton raises an exception:
ACRAApplication onCreate
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_exceptionbutton_click (java line: 226)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
at android.view.ViewGroup.addView(ViewGroup.java:1871)
at android.view.ViewGroup.addView(ViewGroup.java:1851)
at anywheresoftware.b4a.objects.ActivityWrapper.AddView(ActivityWrapper.java:106)
at uk.co.martinpearman.b4a.acrademo.main._exceptionbutton_click(main.java:226)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:54)
at android.view.View.performClick(View.java:2506)
at android.view.View$PerformClick.run(View.java:9112)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
But no crash report is sent to my Google Docs account.
With my java android project the same code would have send a crash report to my Google Docs account and i'd have received an email notification.
I tried different methods to cause the B4A project to crash:
An attempt to divide by zero failed to raise an exception, instead the division produced the result Infinity.
An infinite do while loop eventually force closed the app but again no crash report was sent.
I'm wondering if B4A has it's own exception handling code which sits on top of the native android exception handling and this B4A code is intercepting the exceptions which ACRA would otherwise report?
Martin.