android65536 指令位数,一分钟解决Android 65536问题

原创不易,转载请注明出处,谢谢 O(∩_∩)O

前言

单个dex文件不能超过65536个方法数,这个问题在我们日常开发中是非常常见的,但当我们每次遇到时,又不能及时解决,这里为了便于快速解决,做个笔记,如何一分钟解决65536所带来的问题。

步骤

第一步

在defaultConfig配置中添加 multiDexEnabled true

android {

compileSdkVersion 27

defaultConfig {

applicationId "com.fynnjason.app.androiddexdemo"

minSdkVersion 19

targetSdkVersion 27

versionCode 1

versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

multiDexEnabled true //就是这句,添加进来

}

buildTypes {

release {

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

}

}

第二步

依赖最新的multidex包

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:27.1.1'

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 'com.android.support:multidex:1.0.3' //就是这句,添加进来

}

第三步

自己的Application继承MultiDexApplication

import android.support.multidex.MultiDexApplication;

public class MyApplication extends MultiDexApplication{

@Override

public void onCreate() {

super.onCreate();

}

}

第四步

在AndroidManifest申明自己的Application

package="com.fynnjason.app.androiddexdemo">

android:name=".MyApplication" //就是这句,添加进来

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

这样就解决了Android 65536所带来的问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值