새로운 Android Multidex 지원 라이브러리로 멀티 덱싱을 활성화하는 방법
새로운 Multidex 지원 라이브러리를 사용하여 내 앱 중 하나의 방법 제한을 깨고 싶습니다.
Google은 Android Lollipop을 통해 멀티 덱스를 쉽게 만들 수있는 멀티 덱스 지원 라이브러리를 도입했습니다.
이 라이브러리를 사용하고 멀티 덱스 지원으로 앱을 빌드하려면 어떤 단계가 필요합니까?
편집하다:
Android 5.0 (API 레벨 21) 이상은 멀티 덱싱을 기본적으로 지원하는 ART를 사용합니다. 따라서 minSdkVersion21 이상인 경우 멀티 덱스 지원 라이브러리가 필요하지 않습니다.
당신의 수정 build.gradle:
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
단위 테스트를 실행중인 경우이를 Application클래스 에 포함 시키려고합니다.
public class YouApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
아니면 그냥 application수업을 확장MultiDexApplication
public class Application extends MultiDexApplication {
}
자세한 내용 은 이 안내서를 참조하십시오.
멀티 덱싱을 시작하려면 다음 단계가 필요합니다.
프로젝트에 android-support-multidex.jar를 추가하십시오. jar은 Android SDK 폴더 / sdk / extras / android / support / multidex / library / libs에 있습니다.
이제 응용 프로그램 응용 프로그램 클래스에서 MultiDexApplication을 확장 할 수 있습니다.
public class MyApplication extends MultiDexApplication
또는 다음과 같이 attachBaseContext를 재정의하십시오.
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
재정의 접근법을 사용했는데 응용 프로그램 클래스의 클래스 계층 구조를 망칠 수 없습니다.
이제 앱에서 멀티 덱스를 사용할 수 있습니다. 다음 단계는 gradle에게 multi dexed apk를 만들도록 설득하는 것입니다. 빌드 도구 팀이이 작업을보다 쉽게 수행하기 위해 노력하고 있지만 현재로서는 앱 build.gradle의 Android 부분에 다음을 추가해야합니다.
dexOptions {
preDexLibraries = false
}
다음은 앱 build.gradle의 일반적인 부분입니다.
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
자세한 내용은 Alex Lipovs 블로그를 참조하십시오 .
간단히, 멀티 덱스를 활성화하려면 다음을 수행해야합니다.
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.0'
}
also you must change your manifest file. In your manifest add the MultiDexApplication class from the multidex support library to the application element like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
In your build.gradle add this dependency:
compile 'com.android.support:multidex:1.0.1'
again in your build.gradle file add this line to defaultConfig block:
multiDexEnabled true
Instead of extending your application class from Application extend it from MultiDexApplication ; like :
public class AppConfig extends MultiDexApplication {
now you're good to go! And in case you need it, all MultiDexApplication does is
public class MultiDexApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Step 1: Change build.grade
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
dependencies {
...
compile 'com.android.support:multidex:1.0.0'
}
Step 2: Setting on the Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
MultiDex.install(this);
}
}
Step 3: Change grade.properties
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
It will work!. Thanks.
First you should try with Proguard (This clean all code unused)
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
build.gradle
multiDexEnabled true
implementation 'androidx.multidex:multidex:2.0.1'
AndroidManifest.xml
<application
android:name="androidx.multidex.MultiDexApplication"
If you want to enable multi-dex in your project then just go to gradle.builder
and add this in your dependencie
dependencies {
compile 'com.android.support:multidex:1.0.0'}
then you have to add
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true}
Then open a class and extand it to Application If your app uses extends the Application class, you can override the oncrete() method and call
MultiDex.install(this)
to enable multidex.
and finally add into your manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Add to AndroidManifest.xml:
android:name="android.support.multidex.MultiDexApplication"
OR
MultiDex.install(this);
in your custom Application's attachBaseContext method
or your custom Application extend MultiDexApplication
add multiDexEnabled = true in your build.gradle
defaultConfig {
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
}
just adding this snipped in the build.gradle also works fine
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
**// Enabling multidex support.
**multiDexEnabled true****
}
}
Multi_Dex.java
public class Multi_Dex extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
'IT' 카테고리의 다른 글
| Python-고유 한 사전 목록 (0) | 2020.07.02 |
|---|---|
| 명령 출력에서 두 번째 열을 얻는 방법? (0) | 2020.07.02 |
| C #에서 전월의 첫날과 마지막 날을 가져옵니다. (0) | 2020.07.02 |
| 날짜 시간을 밀리 초 단위로 문자열로 형식화 (0) | 2020.07.02 |
| 파이썬 : print 명령으로 줄 바꾸기 피하기 (0) | 2020.07.02 |