Mix with NDK and SDK does not include Activities

12 views
Skip to first unread message

markus.wiesenbacher

unread,
Sep 24, 2015, 5:39:52 AM9/24/15
to Maven Android Developers
Hi guys,

I am trying to mix native code with java. The APK gets compiled and can be installed, but it crashes as soon as it starts. Error:

09-24 05:32:31.996: E/AndroidRuntime(1151): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.demo.can2s/de.demo.can2s.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "de.demo.can2s.MainActivity" on path: DexPathList[[zip file "/data/app/de.demo.can2s-2.apk"],nativeLibraryDirectories=[/data/app-lib/de.demo.can2s-2, /system/lib]]
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.os.Handler.dispatchMessage(Handler.java:102)
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.os.Looper.loop(Looper.java:136)
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.app.ActivityThread.main(ActivityThread.java:5001)
09-24 05:32:31.996: E/AndroidRuntime(1151): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 05:32:31.996: E/AndroidRuntime(1151): at java.lang.reflect.Method.invoke(Method.java:515)
09-24 05:32:31.996: E/AndroidRuntime(1151): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
09-24 05:32:31.996: E/AndroidRuntime(1151): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
09-24 05:32:31.996: E/AndroidRuntime(1151): at dalvik.system.NativeStart.main(Native Method)
09-24 05:32:31.996: E/AndroidRuntime(1151): Caused by: java.lang.ClassNotFoundException: Didn't find class "de.demo.can2s.MainActivity" on path: DexPathList[[zip file "/data/app/de.demo.can2s.apk"],nativeLibraryDirectories=[/data/app-lib/de.demo.can2s, /system/lib]]
09-24 05:32:31.996: E/AndroidRuntime(1151): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-24 05:32:31.996: E/AndroidRuntime(1151): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
09-24 05:32:31.996: E/AndroidRuntime(1151): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
09-24 05:32:31.996: E/AndroidRuntime(1151): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
09-24 05:32:31.996: E/AndroidRuntime(1151): ... 11 more

This is my maven-config:

<plugin>
 
<groupId>com.simpligility.maven.plugins</groupId>
 
<artifactId>android-maven-plugin</artifactId>
 
<version>${android.plugin.version}</version>
 
<extensions>true</extensions>
 
 
<executions>
     
<execution>
       
<goals>
 
<goal>ndk-build</goal>
       
</goals>
       
<configuration>
 
<ndkFinalLibraryName>Sandbox</ndkFinalLibraryName>
 
<target>CAN2S</target>
 
<clearNativeArtifacts>false</clearNativeArtifacts>
 
<attachNativeArtifacts>true</attachNativeArtifacts>
 
<ndkArchitecture>armeabi-v7a</ndkArchitecture>
 
<nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
       
</configuration>
     
</execution>
   
</executions>


 
<configuration>
 
<sdk>
 
<platform>18</platform>
 
<path>C:/android-sdks</path>
 
</sdk>
 
<ndk>
 
<path>C:/android-ndk-r10e</path>
 
</ndk>
 
<dex>
 
<jvmArguments>
 
<jvmArgument>-Xms256m</jvmArgument>
 
<jvmArgument>-Xmx4096m</jvmArgument>
 
</jvmArguments>
 
<coreLibrary>true</coreLibrary>
 
</dex>
 
<extractDuplicates>true</extractDuplicates>
 
<attachJar>true</attachJar>
 
<deleteConflictingFiles>true</deleteConflictingFiles>
 
<nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
       
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
       
<resourceDirectory>${project.basedir}/res</resourceDirectory>
       
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
   
</configuration>
</plugin>


If I use Project->Android Tools->Export Signed Application Package in Eclipse, it works! The classes.dex is then much bigger!

Anyone already got this problem?

Many thanks and best regards
Markus

William Ferguson

unread,
Sep 24, 2015, 11:58:43 PM9/24/15
to Maven Android Developers
Markus,

are you Proguarding? Make sure that you have excluded your Activity from being obfuscated.

William
Reply all
Reply to author
Forward
0 new messages