2017-07-31 53 views
1

我在我的应用程序中启用了miltidex。 Api 21+工作正常。 的Android API 16原因:Android butterlitife multidex

java.lang.NoClassDefFoundError: ......AuthorizationController 

如果我评论BN结合一切工作正常。 启用Multidex:multiDexEnabled true, compile 'com.android.support:multidex:1.0.1'等等。 有什么办法可以使它工作吗?

编辑

gradle这个

buildscript { 
     repositories { 
      maven { url 'https://maven.fabric.io/public' } 
     } 

     dependencies { 
      classpath 'io.fabric.tools:gradle:1.+' 
     } 
    } 
    apply plugin: 'com.android.application' 
    apply plugin: 'io.fabric' 

    repositories { 
     maven { url 'https://maven.fabric.io/public' } 
    } 


    android { 
     signingConfigs { 
      prod_release { 
... 
      } 
     } 
     compileSdkVersion 25 
     buildToolsVersion "25.0.3" 
     productFlavors { 
      dev { 
       // Enable pre-dexing to produce an APK that can be tested on 
       // Android 5.0+ without the time-consuming DEX build processes. 
       minSdkVersion 16 
       signingConfig signingConfigs.prod_release 
      } 
      prod { 
       // The actual minSdkVersion for the production version. 
       minSdkVersion 16 
       signingConfig signingConfigs.prod_release 
      } 
     } 
     defaultConfig { 
      applicationId "ru.wearemad.gravo" 
      targetSdkVersion 25 
      versionCode 1 
      versionName "1.0" 
      multiDexEnabled true 
      testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     } 
     dexOptions { 
      javaMaxHeapSize "2g" 
      preDexLibraries = false 
     } 
     buildTypes { 
      release { 
       minifyEnabled false 
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
       signingConfig signingConfigs.prod_release 
      } 
      debug { 
       signingConfig signingConfigs.prod_release 
      } 
     } 
    } 

    dependencies { 
     compile fileTree(include: ['*.jar'], dir: 'libs') 
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
      exclude group: 'com.google.code.findbugs' 
      exclude group: 'com.android.support', module: 'support-annotations' 
     }) 
     compile 'com.android.support:appcompat-v7:25.3.1' 
     compile 'com.android.support:design:25.3.1' 
     //retrofit 
     compile 'com.squareup.retrofit2:retrofit:2.3.0' 
     compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' 
     compile 'com.squareup.retrofit2:converter-gson:2.3.0' 
     compile 'com.squareup.okhttp3:logging-interceptor:3.8.0' 
     //rxjava 2 
     compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 
     compile 'io.reactivex.rxjava2:rxjava:2.1.1' 
     //butterknife 
     compile 'com.jakewharton:butterknife:8.7.0' 
     annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0' 
     //mosby + conductor 
     compile 'com.bluelinelabs:conductor-support:2.1.4' 
     compile 'com.hannesdorfmann.mosby3:mvp-conductor:3.0.0' 
     compile 'com.hannesdorfmann.mosby3:viewstate:3.0.4' 
     compile 'com.hannesdorfmann.mosby3:viewstate-conductor:3.0.0' 
     compile 'com.madgag.spongycastle:core:1.54.0.0' 
     compile 'com.madgag.spongycastle:prov:1.54.0.0' 
     compile 'com.madgag.spongycastle:pkix:1.54.0.0' 
     compile 'com.madgag.spongycastle:pg:1.54.0.0' 
     // testCompile 'junit:junit:4.12' 
     compile 'de.hdodenhof:circleimageview:2.1.0' 
     compile 'com.orhanobut:hawk:1.+' 
     compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
      transitive = true; 
     } 
     compile 'com.android.support:multidex:1.0.1' 
    } 

清单的一部分:

<application 
     android:name="ru.wearemad.gravo.MyApplication" 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 

应用类:

public class MyApplication extends MultiDexApplication {...} 

我试图添加multiDexKeepProguard,但是gradle没有看到该方法,或者方法的声明已更改。

编辑2 Butterknife Unbinder其在Bitterknife.bind(返回)使得麻烦。任何想法如何解决?

回答

0

您是否包含以下内容? 如果不重写应用程序类,编辑清单文件设置机器人:在标签名称如下:

<?xml version="1.0" encoding="utf-8"?> 
 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 
    package="com.example.myapp"> 
 
    <application 
 
      android:name="android.support.multidex.MultiDexApplication" > 
 
     ... 
 
    </application> 
 
</manifest>

如果你这样做覆盖应用程序类但不能更改基类,则可以改为覆盖attachBaseContext()方法并调用MultiDex.install(this)以启用multidex:

public class MyApplication extends SomeOtherApplication { 
 
    @Override 
 
    protected void attachBaseContext(Context base) { 
 
    super.attachBaseContext(base); 
 
    MultiDex.install(this); 
 
    } 
 
}

Further read

+0

我已经尝试了这些方法:尝试了我自己的应用程序类,它扩展了MultiDexApplication和super.attachBaseContext(base); MultiDex.install(this); – TooLazy

+0

并在Manifest中注册?

+0

ofc,我还有其他一些代码。 – TooLazy

0

注意如果您的项目配置为multidex用的minSdkVersion 20或更低,并部署到目标上运行的是Android 4.4(API级设备20)或更低,Android Studio禁用即时运行。

更多信息read doc

check my ans it can help you

0

你创建自己的应用程序类,它扩展MultiDexApplication?他们有两个变种来添加multidex支持。这种扩展方式的效果很好,但是需要在attachBaseContext中调用MultiDex.install(this);的变体不起作用。

+0

雅,都尝试过。 – TooLazy

+0

你能分享Gradle文件,清单和应用程序的代码吗?如果能帮助我们更好地理解正在发生的事情。 –