Android multidex不工作
我的争吵如下: 因此,对于一个更大的项目,我需要有多个应用程序,其中包含一个可重用的库模块,用于多种用途。不幸的是,我的库模块中的类和库的基本数量似乎超过了项目的dex限制 具有以下gradle依赖项Android multidex不工作,android,gradle,dex,Android,Gradle,Dex,我的争吵如下: 因此,对于一个更大的项目,我需要有多个应用程序,其中包含一个可重用的库模块,用于多种用途。不幸的是,我的库模块中的类和库的基本数量似乎超过了项目的dex限制 具有以下gradle依赖项 dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'junit:junit:4.12' implementation
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.2.51"
implementation "org.jetbrains.anko:anko:$anko_version"
implementation 'com.android.support:multidex:1.0.3'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'
implementation 'androidx.exifinterface:exifinterface:1.0.0-beta01'
implementation "androidx.browser:browser:1.0.0-beta01"
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.github.ornolfr:rating-view:0.1.2@aar'
implementation 'com.github.siyamed:android-shape-imageview:0.9.3@aar'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
implementation("com.github.bumptech.glide:recyclerview-integration:4.6.1") {
// Excludes the support library because it's already included by Glide.
transitive = false
}
implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
implementation 'io.realm:android-adapters:2.1.1'
}
正如你所看到的,它有很多库(我确实需要)。除此之外,我已经启用了multiDex为true,添加了支持multiDex库(如您在依赖项中所看到的),并且我还使用了一个自定义应用程序类,该类从MultidexApplication扩展而来
但不幸的是,我仍然得到了
Error: Cannot fit requested classes in a single dex file (# methods: 68405 > 65536)
生成期间出错。唯一能解决这个问题的办法是将我的minSDK从19设置为21,但我需要在项目中设置为19
有人知道我可能会尝试修复什么吗?为低于API 21实现多索引需要两个步骤 第一步:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
第二步:
从多索引应用程序中扩展应用程序类
public class MyApplication extends MultiDexApplication { ... }
或者,如果您没有自定义应用程序类,请更改AndroidManifest.xml类,如下所示:
<?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>
...
快乐编码:)您当前使用的是支持多索引库,但您已升级为使用androidx 因此,您需要使用androidx版本 即: 替换
implementation'com.android.support:multidex:1.0.3'
使用
implementation'androidx.multidex:multidex:2.0.0'
implementation'com.google.android.gms:play services vision:15.0.2',这就是问题的根源。请仅使用此库中所需的组件。例如:com.google.android.gms:play services位置:11.8。0@Sudhiplay services愿景是多个库的组合吗?@sixeco简短回答否!长回答是的,但是如果您需要与vision相关的服务,那么您必须导入整个依赖项,因为文档中没有提到任何子模块依赖项。您可以在gradle文件中发布更多信息吗?您找到解决方案了吗?我也有同样的问题,仍然在努力寻找解决方案。正如帖子中所说的,我已经做了所有这些,但我仍然收到了错误。您是否也在defaultConfig
中启用了multiDexEnabled
标志?第二步呢?在您的问题中,您只显示了对multidex
的依赖关系,但完成此过程还需要其他一些东西。