作者:冰_若真人_755_171 | 来源:互联网 | 2022-11-12 11:44
因此,我刚刚达到了我的android项目的最大方法数限制,该项目无法生成并显示以下错误消息:
错误:null,无法在单个dex文件中容纳请求的类(#方法:117407> 65536)
我了解该消息的含义以及如何解决(运行proguard,启用multidex等)。我的问题是我不明白为什么突然收到此消息-我正在做的是删除一些多余的旧代码,点击生成,现在我收到此消息。
问题1:即使我没有添加任何库依赖关系,我的方法计数(根据错误消息为117407)怎么可能突然大大超过限制(65536)?我实际上删除了代码,突然间我喜欢5万种方法?
现在,这真的变得很奇怪:我想分析APK以找出导致问题的原因,但是我当然不能构建它。因此,我没有启用multidex,而是决定将我的代码还原为昨天(绝对可以在昨天进行正确的构建-我的手机上已经安装了该应用程序以证明这一点!),但是仍然收到此构建错误消息。我不知道这怎么可能。我尝试恢复到几天前的同一件事(克隆一个新的repo并签出一个较早的提交)。
因此,问题2:对于昨天刚构建好的没有错误的完全相同的代码,我如何得到此构建错误?
我唯一能想到的是,我用作依赖项的库的大小突然增加了-但是我在gradle构建中声明了所有内容的特定版本,例如:
// RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
因此,我的依赖关系肯定不会改变吗?
我能做些什么来解决这个问题的任何想法都将受到赞赏。我试过清理我的项目,并使android studio中的缓存无效/重启。我真的不想启用multidex或必须在我的调试版本上运行proguard。
这是完整的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "XXXXXXXXX"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true // see https://developer.android.com/studio/write/vector-asset-studio#sloption
}
buildTypes {
release {
minifyEnabled false
// Do code shrinking!
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Core stuff
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
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'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.google.android.gms:play-services-wearable:16.0.1'
// Dagger
implementation 'com.google.dagger:dagger:2.21'
kapt 'com.google.dagger:dagger-compiler:2.21'
// Dagger for Android
implementation 'com.google.dagger:dagger-android:2.21'
implementation 'com.google.dagger:dagger-android-support:2.21' // if you use the support libraries
kapt 'com.google.dagger:dagger-android-processor:2.21'
// Constraint layout
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
// Associated WearOS project
wearApp project(':wear')
// Common library project
implementation project(':common')
// These were added to resolve gradle error on the 'com.android.support:appcompat-v7:28.0.0' implementation:
// All com.android.support libraries must use the exact same version specification (mixing versions can lead to
// runtime crashes). Found versions 28.0.0, 26.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0
// and com.android.support:support-media-compat:26.1.0
// This seems to be related to linking the wear project. If the wear project was not linked, the error went away.
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
// RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
// Retrofit RxJava
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
// Retrofit logging:
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
// Room
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
implementation "android.arch.persistence.room:common:$room_version"
implementation "android.arch.persistence.room:rxjava2:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
// For modern time handling (java.time requires API 26 or higher)
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.1'
// Graphing
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
// Dropbox
implementation 'com.dropbox.core:dropbox-core-sdk:3.0.11'
// OpenCSV
implementation 'com.opencsv:opencsv:4.5'
}
编辑
因此,在启用multidex后,当我使用Android Studio分析APK时,以下TLD下会显示一些严重的依赖关系(不确定是否应该查看已定义或引用的方法编号?):
com.dropbox:26000个定义方法,34000个引用方法
com.android(主要支持库):已定义18700,已引用24600
org.apache(常见,日志等):已定义15000,已引用15700
仅凭这些,我就达到了极限。我仍然不明白为什么这突然发生了:(当然,如果我没有添加任何库,这些数字应该不会改变吗?
1> Driss Baidou..:
简单地将此添加到您的gradle(模块:应用程序)>> multiDexEnabled true
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}
然后在菜单中的Rebuild Project中,单击=> Build> Rebuild Project。