2014-12-17 3 views
1

2 가지 변형 - 시뮬레이터 &이있는 라이브러리가 필요한 애플리케이션을 구축 중입니다.Android Studio - 유사 콘텐츠 및 모듈 선택

내 목표는 assembleSimulatorDebug & assembleDebug와 같은 빌드 작업을 만드는 것입니다. assembleSimulatorDebug에는 시뮬레이터 모듈/라이브러리가 포함되고 assembleDebug에는 apk를 빌드하기위한 실제 모듈이 포함됩니다.

build.gradle의 dependencies 섹션에 else 블록이 있을지 생각 중입니다. 이런 식으로 할 수 있을까요?

나는 이런 식으로 설정하기 위해 어제부터 새로운 것을 시도하고 있습니다. 누군가가 힌트 나 링크를 제공하여 아이디어를 얻을 수 있다면 도움이 될 것입니다.

답변

2

업데이트 : 다른 해결책을 찾았습니다. 그것은 또 다른 대답입니다.

android gradle plugin의 'Flavor products'의 사용법으로 가능합니다. 제품 구현에 따라 라이브러리 구현을 분리 할 수 ​​있습니다.

초기 요구 사항 'com.android.tools.build:gradle:1.0.0', 안드로이드 스튜디오 1.0.1.

나는 project at GitHub을 만들었으므로 배우고 실행하고 배우게됩니다.

앱과 라이브러리의 두 가지 맛을 만들어야합니다. 예를 들어, normalsimulator

응용 프로그램의 build.gradle

apply plugin: 'com.android.application' 

android { 
    lintOptions { 
     abortOnError false 
    } 
    compileSdkVersion 21 
    buildToolsVersion "21.1.1" 

    defaultConfig { 
     applicationId "com.tivogi.gradle" 
     minSdkVersion 15 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    productFlavors { 
     normal { 
     } 
     simulator { 
     } 
    } 

} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:21.0.3' 
    normalCompile project(path: ':library', configuration: 'normalRelease') 
    simulatorCompile project(path: ':library', configuration: 'simulatorRelease') 
} 

도서관의 build.gradle

apply plugin: 'com.android.library' 

android { 
    publishNonDefault true 

    compileSdkVersion 21 
    buildToolsVersion "21.1.1" 

    defaultConfig { 
     minSdkVersion 15 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    productFlavors { 
     normal { 
     } 
     simulator { 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:21.0.3' 
} 

라이브러리 :에 의해 맛과

  • 분할 구현(이에 대한 질문이있는 경우 내 sample project 참조).
  • 도서관의 모든 변종을 게시 할 수도 있습니다 Gradle Plugin User Guide

    에서의 build.gradle

    publishNonDefault true를 추가합니다. 우리는 위와 같이 일반적인 프로젝트 대 프로젝트 의존성을 사용하면서 이것을 허용 할 계획이지만, Gradle의 제한 사항으로 인해 현재로서는 불가능합니다 (우리는이를 수정하기 위해 노력하고 있습니다). 모든 변형 게시는 기본적으로 사용되지 않습니다. 을 사용하려면 :

    안드로이드 {
    publishNonDefault 사실
    }

응용 프로그램 :

  • 이 (productFlavors를) normalsimulator 제품 맛을 추가;
  • 다른 게시 된 유물에 대한 종속성을 만들려면 Gradle Plugin User Guide

    에서 dependencies 섹션

    normalCompile project(path: ':library', configuration: 'normalRelease') 
    simulatorCompile project(path: ':library', configuration: 'simulatorRelease') 
    

    옆에 줄을 추가, 당신은 사용할 하나를 지정해야합니다

    종속 {
    flavor1 컴파일 프로젝트 (경로 : ': lib1', 구성 : 'flavor1Release')
    flavor2Compile 프로젝트 (경로 : 'LIB1'구성 'flavor2Release')이 모든 후
    }

당신이 applicaiton의 2 개 변종 구축 할 수 있습니다 : 정상 및 시뮬레이터를.

+0

고맙습니다. 그것은 일했다 :) –

2

2 개의 라이브러리에 대한 발견 된 솔루션은 더 간단 해 보입니다. 다음을 기반으로합니다. official guide

마지막으로, 제품 유형과 마찬가지로 제품 맛보기는 자체 의존성을 가질 수 있습니다. 예를 들어, 풍미가 광고 기반 앱과 유료 앱을 생성하는 데 사용되는 경우 풍미 중 하나가 광고 SDK에 종속 될 수 있지만 다른 것은 그렇지 않을 수 있습니다.

종속 {
flavor1Compile "..."
}

그래서 만약 당신이 2 개인 라이브러리를 생성하고, 예를 들어,이 맛을 만들 수는 라이브러리 library-normallibrary-simulator하고 맛 normalsimulator 있습니다.

응용 프로그램 build.gradle

apply plugin: 'com.android.application' 

android { 
    lintOptions { 
     abortOnError false 
    } 
    compileSdkVersion 21 
    buildToolsVersion "21.1.1" 

    defaultConfig { 
     applicationId "com.tivogi.gradle" 
     minSdkVersion 15 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    productFlavors { 
     normal { 
     } 
     simulator { 
     } 
    } 

} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:21.0.3' 
    normalCompile project(":library-normal") 
    simulatorCompile project(":library-simulator") 
} 

응용 프로그램 :

  • dependencies으로 만 줄을 추가;

    normalCompile project(":library-normal") 
    simulatorCompile project(":library-simulator") 
    

라이브러리 :

  • 변화를 필요로하지 않는다;

이 솔루션의 예제 프로젝트는 individual-libraries 브랜치에 게시했습니다.

관련 문제