java.lang.NoClassDefFoundError:com / xxx / music / ads / AudioAdManager for Inner project class

时间:2017-02-23 15:21:01

标签: java android

我得到的是类的NoClassDefFoundError,它是我的Android项目的一部分而不是第三方库。 这是错误:

java.lang.NoClassDefFoundError: com/xxx/music/ads/AudioAdManager.......
Caused by: 
java.lang.ClassNotFoundException: Didn't find class "com.xxx.music.ads.AudioAdManager" 

com.xxx.music.player.PlayerService.triggerSomthing()

调用 AudioAdManager 方法
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;
    }
}

这是我的app / 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时,会列出同一个类。

  1. 此处提供的指南multidex from developer.android.com
  2. Article on medium
  3. 示例1 github上的项目https://github.com/frogermcs/HelloMultidex
  4. https://github.com/mmadev/multidex-sample
  5. 上的示例2项目

    有没有人为此工作?我真的很感激。

    感谢。

1 个答案:

答案 0 :(得分:0)

你班上有拼写错误'定义:" class"出现两次。

public class class AudioAdManager
public class class PlaybackService

除了这个(现在已修复)问题,您能解释一下如何调用您的triggerSomthing()方法吗?是在PlaybackService对象上调用,还是试图静态调用它?