0
我得到了一個類的NoClassDefFoundError,它是我的Android項目的一部分,而不是第三方庫。 這是錯誤:java.lang.NoClassDefFoundError:com/xxx/music/ads/AudioAdManager for Inner project class
java.lang.NoClassDefFoundError: com/xxx/music/ads/AudioAdManager.......
Caused by:
java.lang.ClassNotFoundException: Didn't find class "com.xxx.music.ads.AudioAdManager"
的AudioAdManager方法是從com.xxx.music.player.PlayerService.triggerSomthing()
public class AudioAdManager{
static AudioAdManager instance;
public AudioAdManager(){
}
public void doSomething(){
///
}
public static AudioAdManager getInstance(){
if(instance == null){
instance = new AudioAdManager();
}
return instance;
}
}
public class PlaybackService{
static PlaybackService instance;
public PlaybackService(){
}
public void triggerSomthing(){
/// do some other tasks
AudioAdManager.getInstance().doSomething();
}
public static PlaybackService getInstance(){
if(instance == null){
instance = new PlaybackService();
}
return instance;
}
}
稱爲這是我的應用程序/文件的build.gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'io.fabric'
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.xxx"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
debug{
multiDexKeepFile file("multidex.txt")
multiDexKeepProguard file("multidex.keep")
}
release {
minifyEnabled false
multiDexKeepFile file("multidex.txt")
multiDexKeepProguard file("multidex.keep")
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental false
preDexLibraries = false
jumboMode = false
javaMaxHeapSize "4g"
}
sourceSets{
main{
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
xxxxxxxxxxxxx
xxxxxxxxxxxxx
xxxxxxxxxxxxx
xxxxxxxxxxxxx
xxxxxxxxxxxxx
xxxxxxxxxxxxx
xxxxxxxxxxxxx
}
apply plugin: 'com.google.gms.google-services'
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex'
dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString()
}
}
我曾嘗試以下指南和他們都沒有似乎工作:當我嘗試打開app/build/intermediates/multi-dex/debug/maindexlist.txt
,同一班是在那裏列出。
- 導向這裏給出multidex from developer.android.com
- Article on medium
- 在github https://github.com/frogermcs/HelloMultidex
- 例題項目示例1項目上https://github.com/mmadev/multidex-sample
有沒有人有一個變通的呢?我會很感激。
謝謝。
它不應該編譯。 – SantiBailors
@SantiBailors檢查編輯 –
@MutindaBoniface - 我編輯了我的答案。你能否提供完整的堆棧跟蹤? – veebee