Android Studio開發中的構建異常和解決辦法


1. Cannot fit requested classes in a single dex file (# methods: 162837 > 65536 ; # fields: 88354 > 65536)

在app的build.gradle中添加依賴,在defaultConfig中添加以下代碼【注意:必須是app這個module,不能是其他的module】

apply plugin: 'com.android.application'

android {
    defaultConfig {
        //
        multiDexEnabled true
    }
}

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

果你自定義了Application子類,需要在這個子類中重寫一個方法



@Override
public void onCreate() {
    super.onCreate();
    // 主要是添加下面這句代碼
    MultiDex.install(this);
}


問題描述如下

Duplicate class org.intellij.lang.annotations.Identifier found in modules jetified-annotations-12.0.jar (com.intellij:annotations:12.0) and jetified-annotations-13.0.jar (org.jetbrains:annotations:13.0) Duplicate class org.intellij.lang.annotations.JdkCon

解決辦法
在 應用 build.gradle 里添加 如下代碼

configurations {
cleanedAnnotations
compile.exclude group: 'org.jetbrains' , module:'annotations'
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM