AndroidStudio Gradle 세 번 째 통일 관리 에 의존 하 는 실현 방법

6329 단어 AndroidStudioGradle
AndroidStudio 는 gradle 을 사용 하여 프로젝트 구축 을 했 기 때문에 저희 가 app 을 개발 하 는 데 편리 합 니 다.오늘 은 gradle 을 사용 하 는 편리 한 점 을 보 여 드 리 겠 습 니 다.
하나
둘.
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자 가 아 닙 니까?

좋은 웹페이지 즐겨찾기