我有以下的争执:
因此,对于一个更大的项目,我需要有多个应用程序,其中包含一个可重用的库模块,用于几个目的。不幸的是,我似乎超过了我的项目的dex限制,因为我的库模块中只有基本数量的类和库,其中包含以下gradle依赖项
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。
有没有人知道我也可以试着修复它?
发布于 2018-08-03 04:56:59
为以下API 21实现multidex是一个两步过程。
第一步:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
第二步:从MultidexApplication中退出你的应用程序类。
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>
快乐编码:)
发布于 2018-11-11 10:15:07
您当前使用的是support multidex库,但已升级为使用androidx。
因此,您需要使用androidx版本。
即:
替换implementation 'com.android.support:multidex:1.0.3'
使用implementation 'androidx.multidex:multidex:2.0.0'
https://stackoverflow.com/questions/51661848
复制相似问题