API 14上的Multidex问题 - 带有targetSdkVersion的API 19(Android 4.X)27

问题描述 投票:0回答:2

我用过

compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 23
    ...
    multiDexEnabled true
}

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

app级别的build.gradle

<manifest package="com.example"
...
    <application
        android:name=".AppContext"
        ...
    >
>

manifest很长一段时间,因为我的应用程序绝对引用超过64K的方法。现在我已将其更改为Android Studio 3.3.2下的新SDK和multidex lib

compileSdkVersion 27
buildToolsVersion "27.0.3"


defaultConfig {
    minSdkVersion 14
    targetSdkVersion 27
    ...
    multiDexEnabled true
}

dependencies {
    compile 'com.android.support:multidex:1.0.3'
    ...
}

在所有可用的Android 4.X设备上安装时,应用程序开始崩溃。大多数崩溃都有如下堆栈跟踪:

java.lang.RuntimeException:
at android.app.ActivityThread.installProvider (ActivityThread.java:5236)
at android.app.ActivityThread.installContentProviders (ActivityThread.java:4828)
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:4711)
at android.app.ActivityThread.access$1600 (ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1368)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:146)
at android.app.ActivityThread.main (ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative (Native Method)
at java.lang.reflect.Method.invoke (Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099)
at dalvik.system.NativeStart.main (Native Method)
Caused by: java.lang.ClassNotFoundException:
at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass (ClassLoader.java:497)
at java.lang.ClassLoader.loadClass (ClassLoader.java:457)
at android.app.ActivityThread.installProvider (ActivityThread.java:5221)

我找到解决问题的唯一方法是排除

//    compile 'com.android.support:multidex:1.0.3'

来自app级别的build.gradle和改变

public class AppContext extends Application {
...}

public class AppContext extends MultiDexApplication {
...}

它是build tools 27.x.x中的一个错误还是什么!?

android android-4.4-kitkat multidex android-multidex android-4.0.3-ice-cream-sandwich
2个回答
1
投票

你可以这样试试,

1)删除

multiDexEnabled是的

来自app gradle并且只添加

实现'com.android.support:multidex:1.0.3'

到你的应用程序依赖项

像这样

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.heizolscout.itclanbd.heizolscout"
    minSdkVersion 18
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard- 
rules.pro'
    }
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

0
投票

我在其中一个应用中遇到了同样的问题。使用app扩展MultiDexApplication像这样:

public class AppContext extends MultiDexApplication {

  ...

}

并使用像这样的multidex依赖:

compile 'com.android.support:multidex:1.0.3'

没用。

我在Application类中使用MultiDex.install来解决它。像这样的东西:

import android.support.multidex.MultiDex;

public class AppContext extends Application {

   ...

   @Override
   protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.