ClassNotFoundException when trying to put Android component into a library - android

I have two Android projects: an app and a library. The library uses StreamProvider and it is included as an AAR module in the app project. Here are important (changed by me) bits in both projects:
Library project:
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="au.com.a1ict.mylib">
...
<provider
android:name=".provider.StreamProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="com.commonsware.cwac.provider.STREAM_PROVIDER_PATHS"
android:resource="#xml/file_paths"/>
</provider>
build.gradle:
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.commonsware.cwac:provider:0.4.3'
}
provider/StreamProvider.java:
package au.com.a1ict.mylib.provider;
public class StreamProvider extends com.commonsware.cwac.provider.StreamProvider {
public StreamProvider() {
}
}
App project:
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="au.com.a1ict.myapplication">
app/build.gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile project(':app-debug')
}
app-debug/build.gradle: (name chosen by Android Studio when importing the lib):
configurations.maybeCreate("default")
artifacts.add("default", file('app-debug.aar'))
settings.gradle:
include ':app', ':app-debug'
Compilation & linking phase ends up well, just when the app is about to start I see in the logs:
08-31 13:16:30.386 6656-6656/au.com.a1ict.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: au.com.a1ict.myapplication, PID: 6656
java.lang.RuntimeException: Unable to get provider au.com.a1ict.mylib.provider.StreamProvider: java.lang.ClassNotFoundException: Didn't find class "au.com.a1ict.mylib.provider.StreamProvider" on path: DexPathList[[zip file "/data/app/au.com.a1ict.myapplication-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5002)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "au.com.a1ict.mylib.provider.StreamProvider" on path: DexPathList[[zip file "/data/app/au.com.a1ict.myapplication-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
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.ActivityThread.installProvider(ActivityThread.java:4987)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534) 
at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Suppressed: java.lang.ClassNotFoundException: Didn't find class "au.com.a1ict.mylib.provider.StreamProvider" on path: DexPathList[[dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-support-annotations-24.2.0_789c261ae08b7fa204bc7699aff21c5cfe4ba218-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_e6a045dc4d6d599e73e736c6e39e0dcf8f4490fd-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_c96bb2006cae6009a151f1c7452e4a28bb4585dd-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_a0d684a27f515a3bfd5243a957fad78a92e4fbcd-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_369ab9945f1de9068baf3d6bc7fa4d034f59c368-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_2f9cbd5b7b19dc2598fd196e294d333d451c7a47-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-com.android.support-support-vector-drawable-24.2.0_ec6f782152c4bb5e3b0b6840a634e809e68482eb-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-com.android.support-support-v4-24.2.0_3e07c7a20cb62485a70
08-31 13:16:30.426 6656-6656/au.com.a1ict.myapplication D/Error: ERR: exClass=java.lang.ClassNotFoundException
08-31 13:16:30.426 6656-6656/au.com.a1ict.myapplication D/Error: ERR: exMsg=Didn't find class "au.com.a1ict.mylib.provider.StreamProvider" on path: DexPathList[[zip file "/data/app/au.com.a1ict.myapplication-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
08-31 13:16:30.426 6656-6656/au.com.a1ict.myapplication D/Error: ERR: file=BaseDexClassLoader.java
08-31 13:16:30.426 6656-6656/au.com.a1ict.myapplication D/Error: ERR: class=dalvik.system.BaseDexClassLoader
08-31 13:16:30.426 6656-6656/au.com.a1ict.myapplication D/Error: ERR: method=findClass line=56
08-31 13:16:30.426 6656-6656/au.com.a1ict.myapplication D/Error: ERR: stack=java.lang.RuntimeException: Unable to get provider au.com.a1ict.mylib.provider.StreamProvider: java.lang.ClassNotFoundException: Didn't find class "au.com.a1ict.mylib.provider.StreamProvider" on path: DexPathList[[zip file "/data/app/au.com.a1ict.myapplication-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5002)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "au.com.a1ict.mylib.provider.StreamProvider" on path: DexPathList[[zip file "/data/app/au.com.a1ict.myapplication-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
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.ActivityThread.installProvider(ActivityThread.java:4987)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534) 
at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Suppressed: java.lang.ClassNotFoundException: Didn't find class "au.com.a1ict.mylib.provider.StreamProvider" on path: DexPathList[[dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-support-annotations-24.2.0_789c261ae08b7fa204bc7699aff21c5cfe4ba218-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_e6a045dc4d6d599e73e736c6e39e0dcf8f4490fd-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_c96bb2006cae6009a151f1c7452e4a28bb4585dd-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_a0d684a27f515a3bfd5243a957fad78a92e4fbcd-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_369ab9945f1de9068baf3d6bc7fa4d034f59c368-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-internal_impl-24.2.0_2f9cbd5b7b19dc2598fd196e294d333d451c7a47-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-com.android.support-support-vector-drawable-24.2.0_ec6f782152c4bb5e3b0b6840a634e809e68482eb-classes.dex", dex file "/data/data/au.com.a1ict.myapplication/files/instant-run/dex/slice-com.android.support-support-v4-24.2.0_3e07c7a20cb62485a70a27026d0f6ed7d58d351e-classes.dex", dex file "/data/data/au.com.a1i
It must be related to the fact the component (StreamProvider) is located in the AAR file because when used in one project, it works flawlessly (same namespace, packages, ... -- I literally just copy library project's files into app-debug). Related SO questions mostly struggle with Eclipse. I'm really out of ideas here.

OK, this took one hell of an investigation but I have finally figured it out. It was actually a combination of several problems:
AAR doesn't contain information about its dependencies; so I either have to include them manually or setup a maven repository.
First I used maven-publish plugin for that only to realise it doesn't fill out AAR dependencies automatically.
Then I used Gradle Android Maven plugin, much better but:
Latest Gradle Android Maven plugin (1.5) requires Gradle 3.0+ while AS offers/recommends/sets 2.14.1 so I had to downgrade the plugin to 1.4.1
Then I realised that actually I still have to include https://s3.amazonaws.com/repo.commonsware.com dependency url into the app project because POM files do not contain information about repositories, only packages.
After that I finally don't see any crashes. Btw, I didn't have to use
compile ('com.group:artifact:0.0.1#aar'){transitive=true}
form (as suggested all over SO), specifying my dependency as:
compile ('com.group:artifact:0.0.1')
was enough.

Related

trouble using HERE Mobile SDK UI Kit

I am trying to implement new HERE Mobile SDK UI Kit for Android but with no luck.
did everything described in Quickstart text file inside uikit-android-release-1.0.0-78. During gradle compiling
there is no error only when application launched. Pasting logcat errors.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
......................................
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/DividerItemDecoration;
at com.here.msdkui.routing.WaypointList.init(WaypointList.java:48)
at com.here.msdkui.routing.WaypointList.<init>(WaypointList.java:35)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
......................................
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.DividerItemDecoration"
on path: DexPathList[[zip file "/data/app/com.testapp.nav-1/base.apk",
zip file "/data/app/com.testapp.nav-1/split_lib_dependencies_apk.apk",
zip file "/data/app/com.testapp.nav-1/split_lib_slice_0_apk.apk",
zip file "/data/app/com.testapp.nav-1/split_lib_slice_1_apk.apk",
..................................................................
zip file "/data/app/com.testapp.nav-1/split_lib_slice_9_apk.apk"],
nativeLibraryDirectories=[/data/app/com.testapp.nav-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClas
Did you include the android support library in your build?
Seems like you are missing it!

NoClassDefFoundError when updating from mockito 2.9.0 to 2.10.0

I am getting the following error when updating from mockito 2.9.0 to 2.10.0:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/mockito/internal/invocation/realmethod/RealMethod;
at com.android.dx.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:43)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)
at org.mockito.Mockito.mock(Mockito.java:1798)
at org.mockito.Mockito.mock(Mockito.java:1711)
at org.ligi.passandroid.TestApp$createKodein$1$2.invoke(TestApp.kt:28)
at org.ligi.passandroid.TestApp$createKodein$1$2.invoke(TestApp.kt:21)
at com.github.salomonbrys.kodein.bindings.ASingleton.getInstance(bindings.kt:71)
at com.github.salomonbrys.kodein.bindings.NoArgBinding$DefaultImpls.getInstance(Binding.kt:186)
at com.github.salomonbrys.kodein.bindings.ASingleton.getInstance(bindings.kt:65)
at com.github.salomonbrys.kodein.bindings.ASingleton.getInstance(bindings.kt:65)
at com.github.salomonbrys.kodein.internal.KodeinContainerImpl$_transformBinding$1.invoke(KodeinContainerImpl.kt:129)
at com.github.salomonbrys.kodein.KodeinContainer$providerOrNull$1.invoke(KodeinContainer.kt:63)
at com.github.salomonbrys.kodein.Kodein$DefaultImpls.Instance(Kodein.kt:396)
at com.github.salomonbrys.kodein.internal.KodeinImpl.Instance(KodeinImpl.kt:13)
at org.ligi.passandroid.App.onCreate(App.kt:68)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
at android.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:382)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.mockito.internal.invocation.realmethod.RealMethod" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/org.ligi.passandroid.test-1/base.apk", zip file "/data/app/org.ligi.passandroid-1/base.apk"],nativeLibraryDirectories=[/data/app/org.ligi.passandroid.test-1/lib/x86, /data/app/org.ligi.passandroid-1/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
Anyone else getting this? Happening on an android project
Try using mockito-android instead of DexMaker (which doesn't seem to be working anymore for Android instrumentation tests on Mockito 2.10 and higher):
compile "org.mockito:mockito-android:2.11.0"

Android app crashes with ClassNotFoundException on some devices

Hi I am developing andorid applicaiton.I tried to install this application on some devices. It works fine.But on some other devices it crashes with following exception:
07-13 12:28:17.515 17306-17306/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.simple, PID: 17306
java.lang.RuntimeException: Unable to instantiate application
com.example.simple.SampleApplication: java.lang.ClassNotFoundException:
Didn't find class "com.example.simple.SampleApplication" on path:
DexPathList[[zip file
"/data/app/com.example.simple-1/base.apk"],nativeLibraryDirectories=[/data/ap
p/com.example.simple-1/lib/arm,
/data/app/com.example.simple-1/base.apk!/lib/armeabi-v7a, /vendor/lib,
/system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:608)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5013
)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5847)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.jav
a:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.example.simple.SampleApplication" on path: DexPathList[[zip file
"/data/app/com.example.simple-1/base.apk"],nativeLibraryDirectories=[/data/a
pp/com.example.simple-1/lib/arm,
/data/app/com.example.simple-1/base.apk!/lib/armeabi-v7a, /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.newApplication(Instrumentation.java:986)
at android.app.LoadedApk.makeApplication(LoadedApk.java:603)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5013
) 
at android.app.ActivityThread.-wrap1(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5847) 
at java.lang.reflect.Method.invoke(Native Method) 
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.jav
a:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
Suppressed: java.lang.ClassNotFoundException:
com.example.simple.SampleApplication
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
07-13 12:33:17.714 17306-17306/com.example.simple I/RuntimeInit: RuntimeInit: enable FTRACE
I already enabled multiDexEnabled truein my gradle. Need some help to resolve this problem. Thank you.
Add below link under dependencies tag :
compile 'com.android.support:multidex:1.0.1'
Sync and run...
In build.gradle file
dependencies {
...
//Multi Dex
compile 'com.android.support:multidex:1.0.1'
....
}
In sample application class
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(SampleApplication.this);
}
then clean & build project
compile 'com.android.support:multidex:1.0.1'
worked for me...
am trying to run application from mac ( was build on windows ).
It crashes on app launches.
Thanks all..

error when run an Android ndk project

I clone a android project from github, when i run it on my phone, the android monitor says
10-20 10:47:06.280 6789-6789/com.example.castoryan.orb E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.castoryan.orb, PID: 6789
java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-support-annotations-23.2.1_29f2fe0e989481fa50280a028f5e882e46f71793-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-internal_impl-23.2.1_7117fbe4c4e713f034cb1d8c57d472030a47c772-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.2.1_a2ab3f53bcae00d27ab9cfee6bcea6d0e86508d6-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-com.android.support-support-v4-23.2.1_1fa6e3f5d64af6cd0cc82e1ace4c4909c52d1921-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.2.1_f4c2af62f943a2f434d4772015f0efc5b2579810-classes.dex", dex file "/data/data/com.example.castoryan.orb/files/instant-run/dex/slice-com.android.support-animated-vector-drawable-23.2.1_f3bfe73a3edbcdf71557b98c7782ea66834668ed-classes.dex"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64, /vendor/lib64, /system/lib64]]] couldn't find "libmono.so"
at java.lang.Runtime.loadLibrary(Runtime.java:378)
at java.lang.System.loadLibrary(System.java:998)
at com.example.castoryan.orb.MyNDK.<clinit>(MyNDK.java:19)
at com.example.castoryan.orb.MainActivity.onCreate(MainActivity.java:94)
at android.app.Activity.performCreate(Activity.java:6013)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
at android.app.ActivityThread.access$1200(ActivityThread.java:152)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5539)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

How can my library import another library in Android Studio?

I am starting with libraries in Android, and I have managed to import a library in my app in this way:
add the .aar file in the /libs folder
add in build.gradle:
repositories{
flatDir {
dirs'libs'
}
dependencies {
...
compile(name:'mylibrary1',ext:'aar')
}
This works fine, but I made mylibrary2 and repeated steps 1 and 2 in mylibrary1, so now mylibrary1 could use mylibrary2.
In summary I want my app to import mylibrary1 and mylibrary1 to import mylibrary2.
The problem is in my app when I call a method from mylibrary2 I get an exception: java.lang.NoClassDefFoundError, I hope someone can help me
Here is the stackstrace in case it helps:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: ar.com.tally.myapplication, PID: 30197
java.lang.NoClassDefFoundError: Failed resolution of: Lar/com/tally/mylibrary2/Class2;
at ar.com.tally.mylibrary1.Class1.get1(Class1.java:10)
at ar.com.tally.myapplication.MainActivity$1.onClick(MainActivity.java:28)
at android.view.View.performClick(View.java:5076)
at android.view.View$PerformClick.run(View.java:20279)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Caused by: java.lang.ClassNotFoundException: Didn't find class "ar.com.tally.mylibrary2.Class2" on path: DexPathList[[dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-support-annotations-23.2.1_d668123607e57c7aa4406ba98a4276e21606428b-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-internal_impl-23.2.1_eca880fd3aaa2f093d820f9d7b8841aa1fa00b4f-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-intermediates-exploded-aar-mylibrary1_7763b008eb2396101d055fb29b3e03d5ee273add-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.2.1_5e6bcbbe4699b2a562a7ba7b6349f8bbfbef9fb4-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-com.android.support-support-v4-23.2.1_c564c185a6a1edef108674e96bf4712114e0c95a-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-com.android.support-recyclerview-v7-23.2.1_a1ec4cea5854a30b896e5f639d2fd95cd214b2b1-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-com.android.support-design-23.2.1_2c4b9902e86719e2bd0652ddfba695894bed0a47-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.2.1_01059d3db947a24736ebcedd233fd40b734ccf3e-classes.dex", dex file "/data/data/ar.com.tally.myapplication/files/instant-run/dex/slice-com.android.support-animated-vector-drawable-23.2.1_69d3f470bac3bccd2f54179c6363fce8b9091976-classes.dex"],nativeLibraryDirectories=[/vendor/lib, /system/lib, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at ar.com.tally.mylibrary1.Class1.get1(Class1.java:10) 
at ar.com.tally.myapplication.MainActivity$1.onClick(MainActivity.java:28) 
at android.view.View.performClick(View.java:5076) 
at android.view.View$PerformClick.run(View.java:20279) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5910) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) 
Suppressed: java.lang.ClassNotFoundException: Didn't find class "ar.com.tally.mylibrary2.Class2" on path: DexPathList[[zip file "/data/app/ar.com.tally.myapplication-1
So when you made mylibrary2 you changed mylibrary1 also so you need to replace both aars with the new ones clean and build again.
However if you have those libs in the same project as modules i recommend that you import them as projects instead of coping manually.
compile project(':mylibrary1')
compile project(':mylibrary2')
or if in different projects as in this case you can add mavenLocal() in repositories:
repositories {
mavenLocal()
...
}
and in your lib projects you can add the maven plugin:
apply plugin: 'maven'
then you need to call:
gradle install
which will install the libs in your local maven repo. so you don't need to copy them manually

Categories

Resources