How can my library import another library in Android Studio? - android

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

Related

Can't add .so file to Android Studio 3.5.3 using jniLibs

I'm trying to add a .so file to a new Android project. I'm using Android Studio 3.5.3. I've done what was recommended here and here ; so I created folders (jniLibs/arm64-v8a, etc) in src/main and added this to app/build.gradle:
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
I placed the libhl.so file in /app/src/main/jniLibs/arm64-v8a (yes, 64-bit should be ok). The project will compile just fine, but on execution it will show the following error in logcat:
02-17 10:25:31.719 3691-3691/com.example.bmdtest03 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bmdtest03, PID: 3691
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.bmdtest03-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.bmdtest03-2/lib/x86_64, /vendor/lib64, /system/lib64]]] couldn't find "libhl.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:989)
at com.example.bmdtest03.MainActivity.<clinit>(MainActivity.java:14)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1572)
at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Conclusion: the file is there, the source is updated in build.gradle, what am I missing?
You can manually generate the .so file with NDK . Then you can add the lib.so file in your jni folder.
Add the NDK path to your local.properties.
Refer this page : https://developer.android.com/studio/projects/gradle-external-native-builds
If its not works. You can create javah then you can access it.
Link to make javah : https://developer.android.com/training/articles/perf-jni

Activity in dynamic feature not found(ClassNotFound)

done:
generate a release a.abb
use bundletool to convert a.abb to a.apks.
deploy it to device.
problem:
the activity in dynamic feature no found.(but in debug, it's ok)
2019-02-25 20:48:58.429 11164-11164/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.demo.yang.myapplication, PID: 11164
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.demo.yang.myapplication/com.demo.yang.feature.TestActivity}: java.lang.ClassNotFoundException: Didn't find class "com.demo.yang.feature.TestActivity" on path: DexPathList[[zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/base.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.en.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.es.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.ja.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.ko.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.pt.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.ru.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.vi.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.xxhdpi.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.zh.apk"],nativeLibraryDirectories=[/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2839)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.demo.yang.feature.TestActivity" on path: DexPathList[[zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/base.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.en.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.es.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.ja.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.ko.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.pt.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.ru.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.vi.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.xxhdpi.apk", zip file "/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.zh.apk"],nativeLibraryDirectories=[/data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1180)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2829)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6938) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/com.demo.yang.myapplication-mTCYObuADWrZE6proGE_tA==/split_config.en.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:353)
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.<init>(DexFile.java:74)
The fact that the class is found in debug but not in release suggests that it's possibly an issue with your proguard configuration (since Proguard is usually applied only on release builds).
Make sure you have
-keep public class * extends android.app.Activity
in your proguard file to ensure that the Activities are not obfuscated.
Please add this to your build.gradle at dynamic feature you create.
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
What worked for me was: remove all the tags <application> from the dynamic features' AndroidManifest and reunite all the Activities declarations on the application's AndroidManifest.
And before that I follow these migrations steps
I faced and fixed this issue. This problem arises, when you are not setting multiDexEnabled option correctly in your base build.gradle (app level) & the project itself.
defaultConfig {
...
multiDexEnabled true
}
And in dependencies
dependencies{
....
implementation "androidx.multidex:multidex:$multidex_version"
}
And you can extend your application class from MultiDexApplication
class YOUR_APPLICATION_CLASS : MultiDexApplication() {
// Rest of your code
}
In base app Manifest mention above application class like:
<application
android:name=".YOUR_APPLICATION_CLASS"
...
</application>
I paste less code for brevity.

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!

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)

ClassNotFoundException when trying to put Android component into a library

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.

Categories

Resources