AndroidStudio Gradle 세 번 째 통일 관리 에 의존 하 는 실현 방법
6329 단어 AndroidStudioGradle
하나
둘.
3.4.567915.
이 세 편의 글 은 gradle 의 포장 과 프로젝트 의존 관리의 장점 을 잘 설명 하 였 으 며,여러분 은 참고 하여 자신의 개발 효율 을 높이 고 서명 파일 의 안전성 을 강화 할 수 있 습 니 다.
많은 경우 에 우 리 는 AndroidStudio 를 사용 하여 안 드 로 이 드 앱 을 개발 할 때 제3자 라 이브 러 리 를 도입 합 니 다.하나의 procject 에서 우 리 는 많은 module 을 가 질 수 있 습 니 다.모든 module 은 하나의 app 입 니 다.그러나 각 module 은 제3자 에 게 의존 할 때 제3자 에 게 의존 하 는 버 전이 다 를 수 있 습 니 다.매번 사용 하 는 버 전 번 호 를 기억 하 는 것 도 불가능 합 니 다.그래서 제3자 의존 을 통일 적 으로 관리 하 는 것 이 특히 중요 하 다.
우 리 는 의존 하 는 제3 자 를 하나의 gradle 에 집중 시 킨 다음 에 사용 해 야 할 module 에 도입 하면 된다.이렇게 하면 서로 다른 버 전의 관 리 를 편리 하 게 진행 할 수 있다.
우선 프로젝트 다음 에'config.gradle'이라는 파일 을 새로 만 든 다음 에 필요 한 모든 제3자 의존 라 이브 러 리 를 설정 합 니 다.
ext {
android = [
compileSdkVersion: 23,
buildToolsVersion: "24.0.2",
minSdkVersion : 15,
targetSdkVersion : 23,
versionCode : 1,
versionName : "1.0"
]
dependVersion = [
support: "23.4.0"
]
dependencies = [
// ------------- Android -------------
supportV4 : "com.android.support:support-v4:${dependVersion.support}",
appcompatV7 : "com.android.support:appcompat-v7:${dependVersion.support}",
design : "com.android.support:design:${dependVersion.support}",
junit : "junit:junit:4.12",
//------------- -------------
espresso : "com.android.support.test.espresso:espresso-core:2.2.2",
// ------------- -------------
okhttp : 'com.squareup.okhttp3:okhttp:3.3.1',
retrofit : 'com.squareup.retrofit2:retrofit:2.1.0',
// ------------- -------------
fresco : 'com.facebook.fresco:fresco:0.11.0',
animatedGif : 'com.facebook.fresco:animated-gif:0.12.0',
picasso : 'com.squareup.picasso:picasso:2.5.2',
photoView : 'com.github.chrisbanes:PhotoView:1.3.1',
// ------------- RxAndroid -------------
rxAndroid : 'io.reactivex:rxandroid:1.2.1',
rxJava : 'io.reactivex:rxjava:1.2.2',
// ------------- json -------------
fastJson : 'com.alibaba:fastjson:1.1.54.android',
gson : 'com.google.code.gson:gson:2.8.0',
// ------------- log -------------
logger : 'com.orhanobut:logger:1.15',
greendao : 'org.greenrobot:greendao:3.2.0',
// ------------- ButterKnife -------------
butterknife : 'com.jakewharton:butterknife:8.4.0',
butterknifeCompiler : 'com.jakewharton:butterknife-compiler:8.4.0',
// ------------- LeakCanary -------------
leakcanaryAndroid : 'com.squareup.leakcanary:leakcanary-android:1.5',
leakcanaryAndroidNoOp: 'com.squareup.leakcanary:leakcanary-android-no-op:1.5',
]
}
이렇게 해서 우 리 는 모든 의존 라 이브 러 리 를 설정 했다.다음은 필요 한 의존 라 이브 러 리 를 우리 의 module 에 도입 하 는 것 이다.1.우리 프로젝트 의 build.gradle 에 추가
apply from: "config.gradle"
2.우리 모듈 의 build.gradle 에 도입
이것 은 도입 전의 gradle 입 니 다.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.bandeng.bandeng"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.2", {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:23.4.0"
testCompile "junit:junit:4.12"
compile "com.android.support:design:23.4.0"
}
개조 후의 gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
applicationId "com.bandeng.bandeng"
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile(rootProject.ext.dependencies.espresso, {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile rootProject.ext.dependencies.appcompatV7
testCompile rootProject.ext.dependencies.junit
compile rootProject.ext.dependencies.design
//
compile rootProject.ext.dependencies.okhttp
compile rootProject.ext.dependencies.retrofit
//
compile rootProject.ext.dependencies.picasso
// RxJava
compile rootProject.ext.dependencies.rxAndroid
compile rootProject.ext.dependencies.rxJava
// json
compile rootProject.ext.dependencies.gson
// log
compile rootProject.ext.dependencies.logger
}
이렇게 하면 편리 하 게 관리 하고 의존 하 는 제3자 가 아 닙 니까?
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Android Studio에서 Material Icon을 빨리 캡처Android Studio 3.4 기능에 Resource Manager가 추가되었습니다. 이 Resource Manager를 사용하면 Material Icon을 앱에 쉽게 가져올 수 있습니다. Resource Man...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.