unexpected e_machine: 3 in KaliumJNI for Android - java

I'm trying to use the libsodium crypto library (a portable version of NaCl (nacl.cr.yp.to)) on Android but I can't figure out how to properly compile/use the Kalium-JNI language binding.
So far I successufully compiled libsodium as described on the libsodium website. In addition, I used the new android-arm compile script added 3 days ago. As a test I compiled the android-x86 version as well to compare the file sizes of the resulting library files. They differ so this seems to be working.
As a next step I installed KaliumJNI using the newly generated android-arm libsodium files. No problems here.
In my little android-maven test application which basically is a "Hello World" archetype I'm simply trying to generate a new keypair:
import org.abstractj.kalium.keys.KeyPair;
KeyPair Alice = new KeyPair();
IntelliJ succesfully compiled my little program but when I try to run it on my emulator (or on my Nexus S) it crashes. First it crashed because it wasn't able to find the kaliumjni library so I added libtestjni.so (which is the .so library generated by KaliumJNI) to my project properties which fixed this problem. The next error message I got told me that libtestjni.so is not 32bit (I'm running a 64bit Ubuntu 12.04LTS). I don't see why it has to be 32bit but anyway I managed to set up a 32bit Ubuntu 12.04LTS VM and compiled android-arm libsodium and KaliumJNI again to generate a 32bit libtestjni.so file. But when I use this 32bit file in my original application (on my 64bit machine) I receive the following error:
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/IM.CRYPTO-1/libtestjni.so" has unexpected e_machine: 3
at java.lang.Runtime.loadLibrary(Runtime.java:364)
at java.lang.System.loadLibrary(System.java:526)
at org.abstractj.kalium.NaCl.<clinit>(NaCl.java:36)
at org.abstractj.kalium.keys.KeyPair.<init>(KeyPair.java:36)
at IM.CRYPTO.HelloAndroidActivity.buttonClick(HelloAndroidActivity.java:43)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
I've spent hours to get to this point but right now I'm clueless where I should go from here. It seems that e_machine: 3 stands for some kind of architecture issue but I can't figure out where I went wrong. The application is compiled for Android 4.0 (Android API 14) and the emulator is configured to use arm and the same API 14 as well (The Nexus phone runs CM with Android 4.3.1). As mentioned before libsodium was compiled for arm as well.
Some more information:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>IM.CRYPTO</groupId>
<artifactId>cryptolibAndroid</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>cryptolibAndroid</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version> 4.0.1.2
</platform.version>
<android.plugin.version>3.6.0</android.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.abstractj.kalium</groupId>
<artifactId>kalium-jni</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
<attachJar>true</attachJar>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>14</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
NaCl.java
(this class gets called to load testjni (KaliumJNI))
package org.abstractj.kalium;
public class NaCl {
public static Sodium sodium() {
return SingletonHolder.SODIUM_INSTANCE;
}
private static final String LIBRARY_NAME = "sodium";
private static final class SingletonHolder {
public static final Sodium SODIUM_INSTANCE = new Sodium();
}
private NaCl() {
}
static {
System.loadLibrary("testjni");
}
}
I'm grateful for any hints to point me into the right direction.
Please note that I have a little JAVA desktop application as well which uses libsodium + Kalium (NOT KaliumJNI) and runs without any problems.

As Alex Cohn hinted at: The library (.so-file) is compiled for the Intel x86 architecture while the device (or emulator) you are trying to run the app on uses some other architecture (assuming ARM). So the relevant line in the output you posted is:
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app-lib/IM.CRYPTO-1/libtestjni.so" has unexpected e_machine: 3
How did you compile the library? Usually, you download the Android NDK and use some provided Makefile (named Android.mk) to compile the library. Do not use the compiler shipped with your Linux-Distribution (called host compiler) to generate libraries that are thought to run on an Android-device.

Related

Android App Crashes on Real Device If apk is manually installed

My Application is running fine in Emulators and even in real devices installed by android studio for debugging purpose, but it is crashing if installed manually using apk file.
I am ready to paste any other codes, like Activity if required.
Here is the logcat:
04-14 12:20:44.392 6220-6220/? I/art: Late-enabling -Xcheck:jni
04-14 12:20:44.465 6220-6220/test.planner W/System: ClassLoader referenced unknown path: /data/app/test.planner-1/lib/arm
04-14 12:20:44.467 6220-6220/test.planner I/InstantRun: starting instant run server: is main process
04-14 12:20:44.470 6220-6220/test.planner D/AndroidRuntime: Shutting down VM
04-14 12:20:44.471 6220-6220/test.planner E/AndroidRuntime: FATAL EXCEPTION: main
Process: test.planner, PID: 6220
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{test.planner/test.planner.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "test.planner.MainActivity" on path: DexPathList[[zip file "/data/app/test.planner-1/base.apk"],nativeLibraryDirectories=[/data/app/test.planner-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "test.planner.MainActivity" on path: DexPathList[[zip file "/data/app/test.planner-1/base.apk"],nativeLibraryDirectories=[/data/app/test.planner-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Suppressed: java.lang.ClassNotFoundException: test.planner.MainActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Just go to:
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
and disable instant run.
If you just upgraded your android studio.
You will not have this option to disable -> Instant Run. (not on the menu)
Seems like with new android studio and gradle upgrade in order to install an apk you need to properly build it.
Option 1: with gradle from command line
./gradlew :appName:clean
./gradlew :appName:build
Option 2: from android studio
Android Studio -> build -> build APK (or generate sighed APK)
The generated apk can be installed fine on a device.
Note: if you start a new applicate with this version of android studio you will see that when you run from studio there is no apk generated anymore.
I faced the similar problem.
Note the size of Apk, it would be very small in size , this is because of the instant run feature in enabled. Just disable it
May be Android Studio is not including all files in Apk, when we use the instant run to fasten the process.
Any body know why this happening?
Go to :
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
and disable instant run.

ApplicationClass ClassNotFoundException

I'm using the application class , so I had to create the manifest file, as follows:
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
I have to work normally without problems when testing , often the error occurred in the Google Play Store error report.
But the error report is posted on the Android version 4.4 , I even tested at 4.4 operate normally.
If the person experiencing this problem help me.
java.lang.RuntimeException: Unable to instantiate application com.moonae.android.common.ApplicationClass: java.lang.ClassNotFoundException: Didn't find class "com.culturelandnew.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4524)
at android.app.ActivityThread.access$1500(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.moonae.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:993)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
is this a typo? i have not seen this before i mean android.name to android:name..btw
quick suggestion, remove your application tag, and use the eclipse gui side to search the application class and reference it.. mostly it references the it without package name included.. like this.. =>
<application
android:name="ApplicationClass"
android:icon="#drawble/ic_launcher"
android:largeHeap="true"
....>

DrawerLayout not found in Android Maven project at runtime

Okay, so I've been trying to figure out this problem for a few weeks now and been on StackOverflow profusely viewing similar problems and trying to apply them to my own situation to no avail. I am worried I am just doing something incredibly stupid or forgetting something stupid and will waste someone's time but I'm out of options and ideas at this point, so apologies if that ends up being the case. I'm not using Eclipse or Android Studio, just CLI Maven. I need to use the DrawerLayout in my app, but the app crashes when attempting to instantiate it due to not being able to find the class (and presumably the rest of the support-v4 package) at runtime. So, step by step.
Here's the line of code that creates the DrawerLayout:
DrawerLayout drawer = new android.support.v4.widget.DrawerLayout(this);
Here's the stack trace of how the app crashes when it tries to create a new instance of the DrawerLayout.
E/AndroidRuntime( 2065): FATAL EXCEPTION: main
E/AndroidRuntime( 2065): Process: com.patron.main, PID: 2065
E/AndroidRuntime( 2065): java.lang.NoClassDefFoundError: android.support.v4.widget.DrawerLayout
E/AndroidRuntime( 2065): at com.patron.main.FlashMenu.onCreate(FlashMenu.java:120)
E/AndroidRuntime( 2065): at android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime( 2065): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime( 2065): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
E/AndroidRuntime( 2065): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime( 2065): at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime( 2065): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime( 2065): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 2065): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 2065): at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 2065): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 2065): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 2065): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 2065): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
W/ActivityManager( 1228): Force finishing activity com.patron.main/.FlashMenu
Here's how I'm including the dependency in my POM.xml:
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-v4</artifactId>
<version>21.0.3</version>
<type>aar</type>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
I'm using the local maven repository provided by google in the android-sdk/extras/android/m2repository folder as suggested by another SO post. Obviously it can compile and run ok so I'm confident it's finding it properly. When I call mvn dependency:build-classpath to see the compile-time classpath, it shows me this:
And then manually opening that AAR folder in 7zip and checking the classes jar to ensure the DrawerLayout is in there, I can see it most certainly is:
So at this point I am unsure what I can change or do to get this support package available at runtime. I went over the classpath in detail and I am confident I am not importing the support-v4 package twice, just once, and judging by the nature of errors from importing it twice I don't think I'd be able to compile if that were the problem. I tried manually setting the scope of the dependency to compile (which should be the right one), then to runtime and provided just in case without any luck. If anyone has any ideas as to what the problem could be to solve this NoClassDefFoundError, it would be most appreciated.
Figured it out. For posterity:
You need to update to the latest version of the Android Maven Plugin, in order to avoid this error. In addition, an old bug I was running into where ActivityCompat21 was not being found along several other classes that I fixed with a hacky workaround is also fixed by updating to version 4.0.0-rc2 of the plugin.
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.0.0-rc.2</version>
<extensions>true</extensions>
<configuration>
<includeLibsJarsFromAar>true</includeLibsJarsFromAar>
</configuration>
</plugin>

Vitamio Sample Error - java.lang.UnsatisfiedLinkError: Couldn't load vinit findLibrary returned null

I'm having trouble running the vitamio-sample from https://github.com/yixia/VitamioBundle.
I am building it with Android Studio and it compiles fine and runs, but when it gets to this line:
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
It throws an exception when I run it on my Nexus 5 (and also on a Galaxy S4):
01-22 11:58:40.759 12323-12323/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: io.vov.vitamio.demo, PID: 12323
java.lang.UnsatisfiedLinkError: Couldn't load vinit from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/io.vov.vitamio.demo-1.apk"],nativeLibraryDirectories=[/data/app-lib/io.vov.vitamio.demo-1, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at io.vov.vitamio.Vitamio.<clinit>(Vitamio.java:258)
at io.vov.vitamio.LibsChecker.checkVitamioLibs(LibsChecker.java:40)
at io.vov.vitamio.demo.VitamioListActivity.onCreate(VitamioListActivity.java:40)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
The exception also happens when I'm running the v4.2.0 tree in my own app.
Any idea what I'm missing? In my own app I pulled the vitamio project into a libraries folder and am referencing it like this:
compile(project(':libraries:vitamio'))
The sample project is left as-is.
I am not sure if there is a cleaner way in the newer version of Vitamino (or gradle). But here is how I got it to work with gradle build tools 0.6.
Added a project to my /libraries directory with the vitamino source/sdk. This has a /libs/armeabi /libs/armeabi-v7a with libvinit.so inside.
In my build.gradle for my main project, reference the library project like:
dependencies {
// other dependencies
compile(project(':libraries:vitamio'))
}
Add the following to the bottom of my build.gradle
task copyNativeLibs(type: Copy) {
from(new File(project(':libraries:vitamio').getProjectDir(), 'libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniDir new File(buildDir, 'native-libs')
}
Then when i run a clean and rebuild it will copy the native libs to the proper spot and include them in the build.

NullPointerException in Android when declaring a Content Provider

I'm facing a strange issue when declaring a Content Provider in my project. I'm copying the classes and Manifest declaration from another project of my own. It's working OK on my other project.
Here's part of my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.qr"
android:installLocation="auto"
android:versionCode="540"
android:versionName="5.4" >
(...)
<application
android:name=".Application"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/ic_launch" >
(...)
<provider
android:name=".provider.HistoryProvider"
android:authorities="com.example.qr.History"
android:exported="true"
android:multiprocess="true"
android:readPermission="com.example.qr.History.read"
android:writePermission="com.example.qr.History.write" />
(...)
</application>
</manifest>
When I run my app, I get this stack trace:
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.ActivityThread.installProvider(ActivityThread.java:4783)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4430)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4372)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
This is the whole stack trace. No 'com.example' trace is included. Of course some code in my app is producing this but the actual crash happens in Android.
Because my own classes are not included in the stack trace, I really don't know where to look.
I've run the code in an emulator with Android 4.2 and I've compared it with the source code of that version of Android, so I know the crash is produced in this line of ActivityThread:
4782 ApplicationInfo ai = info.applicationInfo;
4783 if (context.getPackageName().equals(ai.packageName)) {
Here's a link to the source code of this class.
If I don't declare the content provider (i.e. if I remove from my Manifest), the app works perfectly.
I've added some logs to my Application class, as well as the main Activity class. The crash is produced before either is launched.
So, my question is: what in my code can be producing context, context.getPackageName() or info.applicationInfo to be null during installation?
EDIT
When triggering the stack trace in the emulator several times, I only get this between traces:
09-11 23:10:21.250: E/AndroidRuntime(933): at dalvik.system.NativeStart.main(Native Method)
09-11 23:10:21.470: D/dalvikvm(933): GC_CONCURRENT freed 142K, 9% free 2951K/3224K, paused 78ms+3ms, total 225ms
09-11 23:10:44.030: I/Process(933): Sending signal. PID: 933 SIG: 9
09-11 23:10:46.940: D/dalvikvm(947): GC_CONCURRENT freed 164K, 10% free 2711K/2996K, paused 13ms+114ms, total 201ms
09-11 23:10:47.170: I/ActivityThread(947): Pub com.example.qr.History: com.example.qr.provider.HistoryProvider
09-11 23:10:47.170: D/AndroidRuntime(947): Shutting down VM
09-11 23:10:47.170: W/dalvikvm(947): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
09-11 23:10:47.180: E/AndroidRuntime(947): FATAL EXCEPTION: main

Categories