fix: 解决dex超过64k问题

This commit is contained in:
niushuai233 2022-10-17 17:39:49 +08:00
parent 7278eb371b
commit d0e2652ef0
2 changed files with 22 additions and 2 deletions

View File

@ -12,6 +12,8 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@ -29,6 +31,10 @@ android {
buildFeatures { buildFeatures {
viewBinding true viewBinding true
} }
dexOptions {
javaMaxHeapSize "4g"
}
} }
dependencies { dependencies {
@ -42,9 +48,15 @@ dependencies {
implementation 'androidx.navigation:navigation-ui:2.5.2' implementation 'androidx.navigation:navigation-ui:2.5.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0' implementation 'androidx.gridlayout:gridlayout:1.0.0'
// hutool
implementation 'cn.hutool:hutool-all:5.8.8'
// dex文件数超过64k问题
implementation 'com.android.support:multidex:1.0.1'
//
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'cn.hutool:hutool-all:5.8.8'
} }

View File

@ -1,6 +1,8 @@
package cc.niushuai.project.devcontrol; package cc.niushuai.project.devcontrol;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.multidex.MultiDex;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController; import androidx.navigation.NavController;
@ -67,4 +69,10 @@ public class MainActivity extends AppCompatActivity {
// 底部栏显示 // 底部栏显示
NavigationUI.setupWithNavController(activityMainBinding.bottomNavView, navController); NavigationUI.setupWithNavController(activityMainBinding.bottomNavView, navController);
} }
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}
} }