2017-09-16 102 views
0

我知道這個問題已被問及一百萬次,但我找不到我的具體情況的答案。我有一個包含所有代碼的庫以及一些導入庫的其他模塊。java.lang.RuntimeException:無法實例化應用程序。 ClassNotFoundException:沒有找到類

-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 

而這兩個清單使用這樣的基本應用程序。

<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"> 

而構建依賴關係是這樣的:

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

我的基本應用程序的方法來初始化multidex:

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

我的一些proguard的規則,我已經在兩個加地點(圖書館和應用程序)。這些不包括第三方庫和我自己的一些類的一些規則。

-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.**{ *; } 

所以應用程序運行在我的S8罰款,但不會在某些手機上,如摩托G.他們也會如果Proguard的啓用和資源萎縮,像發佈版本運行正常。我注意到的另一個奇怪的行爲是,當我在我的代碼的某些部分設置斷點並運行發佈版本(可調試設置爲true)時,它會在s8上打破,但不會在moto上打破。

爲什麼這種奇怪的行爲?另一個我發現超類似的問題是unable to instantiate application - ClassNotFoundException。但仍然沒有解決。

這是錯誤的完整日誌。忽略軟件包名稱。 Exception log

編輯

改變我編譯我的應用程序庫的方式,基於從@Mostafa安特suggestiongs後:

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

它開始給我這個錯誤。我有我的即時運行關閉。

Class not found exception on Firebase.initProvider

+0

你能顯示ClassNotFoundException的logcat詳細信息嗎? – JRG

回答

0

化妝基類Application然後onCreate方法調用這一行MultiDex.install(this);

修改模塊級的build.gradle文件以啓用multidex並添加multidex庫作爲依賴性,內部,如圖 延伸在這裏:

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

dependencies { 
    compile 'com.android.support:multidex:1.0.1' 
} 
+0

已經這麼做了。 – user2130331

+0

你在使用proguard嗎?如果是提供給我們的規則 –

+0

嘗試將此行添加到progaurd -keep public class your_missing_class_full_name –

0

如果使用JavaVersion.VERSION_1_8請確保您在所有模塊

使用
android { 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_8 
     targetCompatibility JavaVersion.VERSION_1_8 
    } 
} 
相關問題