0

I know this question has been asked a million times and yet, I couldn't find the answer to my specific situation. I have a library which has all of the code, and a couple of other modules that import the library.

-project
--mylibrary
---sr/main/java
----co/android/mylibrary
----BaseApp (extends MultidexApp)
--Application1
---sr/main/java
----co/android/app2
-----Android Manifest
--Application2
---sr/main/java
----co/android/app2
-----Android Manifest

And both the manifests use the base app like this.

<application
    android:name="co.android.mylibrary.BaseApp"
    android:allowBackup="false"
    android:fullBackupContent="false"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/AppTheme"
    tools:replace="android:icon,android:theme, android:allowBackup">

And the build dependencies look like this:

dependencies {
  releaseCompile project(path: ':mylibrary', configuration: 'release')
  debugCompile project(path: ':mylibrary', configuration: 'debug')
}

My base app's method to initialize multidex:

protected void attachBaseContext(Context base) {   
    super.attachBaseContext(base);
    try {
      MultiDex.install(this);
    }catch (RuntimeException e){}
}

Some of my proguard rules, that I've added at both locations (library and the application). These don't include some rules for 3rd party libraries and some of my own classes.

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View 
-keep public class co.android.mylibrary.data.greendao.**{ *; }

So the app runs fine on my s8, but doesn't on some phones like the moto G. They would also run fine if Proguard is enabled and its shrinking resources, like for release builds. Another strange behavior I noticed is that, when I set my breakpoint on some parts of my code and run the release builds (with debuggable set to true), it would break on the s8, but not on the moto.

Why this strange behavior? Another question that I found super similar is unable to instantiate application - ClassNotFoundException. But still no resolution.

This is the complete log of the error. Ignore the package names. Exception log

Edit

After changing the way I compile the library on my application, based on suggestiongs from @Mostafa Anter:

compile project(path: ':mylibrary', configuration: 'debug')

It started giving me this error. I have my instant run turned off.

Class not found exception on Firebase.initProvider

someuser
  • 43
  • 1
  • 8

2 Answers2

1

make base class extend Application then inside onCreate method call this lineMultiDex.install(this);

Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:

android {
defaultConfig {
    ...
    minSdkVersion 15 
    targetSdkVersion 26
    multiDexEnabled true
}
...
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}
Mostafa Anter
  • 3,445
  • 24
  • 26
  • are you using proguard ? if yes provide us with rules – Mostafa Anter Sep 16 '17 at 21:21
  • try add this line to progaurd -keep public class your_missing_class_full_name – Mostafa Anter Sep 16 '17 at 21:31
  • No. That didn't help. I added something like -keep public class co.android.mylibrary.BaseApp. Also, this is on debug builds, I don't think it even matters, since shrinking is disabled. – someuser Sep 16 '17 at 21:39
  • With shrinking enabled, it runs the app. But doesn't break at some codes, where I want it to, which is causing strange behavior on some devices. – someuser Sep 16 '17 at 21:42
  • try to replace releaseCompile project(path: ':mylibrary', configuration: 'release') debugCompile project(path: ':mylibrary', configuration: 'debug') with compile project(':mylibrary') – Mostafa Anter Sep 16 '17 at 21:46
  • remove to line then put one line compile project(':mylibrary') – Mostafa Anter Sep 16 '17 at 21:46
  • Now Im getting: java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: Have disabled instant run. – someuser Sep 16 '17 at 21:59
0

if you use JavaVersion.VERSION_1_8 please be sure that you use it in all modules

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
yoAlex5
  • 29,217
  • 8
  • 193
  • 205