Multi-project setup with Gradle for Android

ε祈祈猫儿з 提交于 2019-12-22 18:18:52

问题


I am having a problem to make my Android application build.

I have one Main application module, and another one that is needed for the google-play-services_lib.

My folder structure is as follows:

ParkingApp
   | 
   |-----> google-play-services_lib (Library Project) 
   |-----> ParkingApp
   |-----> settings.gradle

My settings.gradle file is as follows:

include ':ParkingApp', ':google-play-services_lib'

My ParkingApp has the following build.gradle.

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile project(':google-play-services_lib')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 17
    }
}

And the google-play-services_lib has the following build.gradle:

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android-library'

dependencies {
    compile files('libs/google-play-services.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 17
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

Any help is appreciated!


回答1:


With the new updates in Android Studio and Gradle, I think a better solution for adding support package and google play services jars is to use the maven repositories instead of adding the library it self, here is how you can add both to any .gradle file, using this way you will no have more problems adding both to dependent projects.

dependencies {
    compile 'com.google.android.gms:play-services:3.1.36'
    compile 'com.android.support:support-v4:13.0.+'
}

Note: In the new version of Android Studio 0.2.0, you will need also to update the gradle verison to:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}



回答2:


Put google-play-services.jar in MyParkingApp/libs and reference it as a dependency from MyParkingApp/build.gradle.



来源:https://stackoverflow.com/questions/16759364/multi-project-setup-with-gradle-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!