2016-06-03 5 views
0

MultiDex에 어려움이 있습니다. Gradle (multiDexEnabled true)에서 활성화했으며 주류는 attachBaseContextMultiDex.install입니다.Gradle 및 ProGuard의 MultiDex 문제

나는 MultiDexExtractor 클래스를 첫 번째 덱스 파일에 추가하지 않는다고 생각합니다 (maindexlist_deobfuscated.txt에 없음). 로그에서

발췌문 :

06-03 07:56:59.030 4088-4088/xxx.android I/dalvikvm: Could not find method android.support.multidex.MultiDexExtractor.verifyZipFile, referenced from method android.support.multidex.MultiDex.checkValidZipFiles 
06-03 07:56:59.030 4088-4088/xxx.android W/dalvikvm: VFY: unable to resolve static method 195: Landroid/support/multidex/MultiDexExtractor;.verifyZipFile (Ljava/io/File;)Z 
06-03 07:56:59.030 4088-4088/xxx.android D/dalvikvm: VFY: replacing opcode 0x71 at 0x0010 

예외 :

06-03 07:56:59.030 4088-4088/xxx.android E/AndroidRuntime: FATAL EXCEPTION: main 
                        java.lang.NoClassDefFoundError: android.support.multidex.MultiDexExtractor 
                         at android.support.multidex.MultiDex.install(Unknown Source) 
                         at xxx.android.AndroidLauncher.attachBaseContext(Unknown Source) 
                         at android.app.Activity.attach(Activity.java:4965) 
                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2008) 
                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
                         at android.app.ActivityThread.access$600(ActivityThread.java:130) 
                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
                         at android.os.Handler.dispatchMessage(Handler.java:99) 
                         at android.os.Looper.loop(Looper.java:137) 
                         at android.app.ActivityThread.main(ActivityThread.java:4745) 
                         at java.lang.reflect.Method.invokeNative(Native Method) 
                         at java.lang.reflect.Method.invoke(Method.java:511) 
                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                         at dalvik.system.NativeStart.main(Native Method) 

내가 (방법을 모르고) Gradle을에 의해 생성되거나 다른 곳에서 문제가되는 목록을 수정해야합니까? MultiDex와 함께 작동하게하려면 어떻게해야합니까?

추 신 : ProGuard를 사용하고 있습니다. 나는 것들로 듣는 것이 아니라, 여기에 확실하게 MultiDex의 일부라고 생각합니다 :

-keep class android.support.multidex.** 
-keepclassmembernames class android.support.multidex.**{*;} 
-keepclassmembers class android.support.multidex.** {*;} 

편집 : 여기 안드로이드 파일 (그것은 주로 libGDX 부트 스트랩 응용 프로그램에 의해 생성 된 것)된다

android { 
    buildToolsVersion "23.0.1" 
    compileSdkVersion 23 
    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src'] 
      aidl.srcDirs = ['src'] 
      renderscript.srcDirs = ['src'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['assets'] 
      jniLibs.srcDirs = ['libs'] 
     } 

     instrumentTest.setRoot('tests') 
    } 

    lintOptions { 
     abortOnError false // make sure you're paying attention to the linter output! 
    } 

// FIXME: How can we apply this simply for all builds? Copy-pasta makes me sad. 
    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFile getDefaultProguardFile('proguard-android-optimize.txt') 
      proguardFile 'proguard-project.txt' 
     } 
     debug { 
      minifyEnabled true 
      proguardFile getDefaultProguardFile('proguard-android-optimize.txt') 
      proguardFile 'proguard-project.txt' 
     } 
    } 

    dexOptions { 
     javaMaxHeapSize "6g" 
    } 

    packagingOptions { 
     exclude 'rootdoc.txt' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
     exclude 'META-INF/services/javax.script.ScriptEngineFactory' 
    } 

    defaultConfig { 
     minSdkVersion 14 
     targetSdkVersion 23 
     multiDexEnabled true 
    } 

    dexOptions { 
     preDexLibraries = false 
    } 
} 

// called every time gradle gets executed, takes the native dependencies of 
// the natives configuration, and extracts them to the proper libs/ folders 
// so they get packed with the APK. 
task copyAndroidNatives() { 
    file("libs/armeabi/").mkdirs(); 
    file("libs/armeabi-v7a/").mkdirs(); 
    file("libs/x86/").mkdirs(); 

    configurations.natives.files.each { jar -> 
     def outputDir = null 
     if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a") 
     if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi") 
     if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86") 
     if (outputDir != null) { 
      copy { 
       from zipTree(jar) 
       into outputDir 
       include "*.so" 
      } 
     } 
    } 
} 
task run(type: Exec) { 
    def path 
    def localProperties = project.file("../local.properties") 
    if (localProperties.exists()) { 
     Properties properties = new Properties() 
     localProperties.withInputStream { instr -> 
      properties.load(instr) 
     } 
     def sdkDir = properties.getProperty('sdk.dir') 
     if (sdkDir) { 
      path = sdkDir 
     } else { 
      path = "$System.env.ANDROID_HOME" 
     } 
    } else { 
     path = "$System.env.ANDROID_HOME" 
    } 

    def adb = path + "/platform-tools/adb" 
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'xxx.android/xxx.android.AndroidLauncher' 
} 
// sets up the Android Eclipse project, using the old Ant based build. 
eclipse { 
    // need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin 
    // ignores any nodes added in classpath.file.withXml 
    sourceSets { 
     main { 
      java.srcDirs "src", 'gen' 
     } 
    } 

    jdt { 
     sourceCompatibility = 1.6 
     targetCompatibility = 1.6 
    } 

    classpath { 
     plusConfigurations += [project.configurations.compile] 
     containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES' 
    } 

    project { 
     name = appName + "-android" 
     natures 'com.android.ide.eclipse.adt.AndroidNature' 
     buildCommands.clear(); 
     buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder" 
     buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder" 
     buildCommand "org.eclipse.jdt.core.javabuilder" 
     buildCommand "com.android.ide.eclipse.adt.ApkBuilder" 
    } 
} 
// sets up the Android Idea project, using the old Ant based build. 
idea { 
    module { 
     sourceDirs += file("src"); 
     scopes = [COMPILE: [plus: [project.configurations.compile]]] 

     iml { 
      withXml { 
       def node = it.asNode() 
       def builder = NodeBuilder.newInstance(); 
       builder.current = node; 
       builder.component(name: "FacetManager") { 
        facet(type: "android", name: "Android") { 
         configuration { 
          option(name: "UPDATE_PROPERTY_FILES", value: "true") 
         } 
        } 
       } 
      } 
     } 
    } 
} 

dependencies { 
    compile 'com.android.support:multidex:1.0.1' 
    compile fileTree(dir: 'libs_jar', include: '*.jar') 
} 

추 신 : 종속성에 multidex 라이브러리를 추가하면 차이가없는 것처럼 보입니다.

+2

당신의 build.gradle 어디 안드로이드 태그에 너무이 추가 선택? –

+0

그래 플 파일을주세요? –

+0

@SohailZahid 질문에 파일을 추가했습니다 :). – monnef

답변

0

MultiDexApplication으로 응용 프로그램 클래스를 확장 했습니까?

예인 경우 build.gradle 파일을 게시하십시오.

댓글 권한이 없으므로 링크를 게시하는 이유입니다. 이 link

+1

"주 클래스가 AttBaseContext에서 MultiDex.install을 호출 중"- 응용 프로그램 클래스 확장에서만 수행 할 수 있습니다. –

0

android { 
    ... 
    afterEvaluate { 
      tasks.matching { 
       it.name.startsWith('dex') 
      }.each { dx -> 
       if (dx.additionalParameters == null) { 
        dx.additionalParameters = ['--multi-dex'] 
       } else { 
        dx.additionalParameters += '--multi-dex' 
       } 
      } 
     } 
} 
+0

정확히 같은 오류입니다. 나는'multiDexEnabled true'가 모든 것을 자동으로 설정한다고 생각한다. – monnef

관련 문제