-
Notifications
You must be signed in to change notification settings - Fork 193
Solving Android Gradle Conflicts
Once of the most common build-issues with Android apps are gradle conflicts between modules specifying different versions of:
compileSdkVersion
buildToolsVersion
- Google
play-services
/firebase
version. - Google support libraries (ie
appcompat-v4
,appcompat-v7
)
Often the solution has been to either fork a Github project or use the gradle exclude
/ force
directives:
compile(project(':react-native-device-info')) {
exclude group: 'com.google.android.gcm'
}
compile ("com.google.android.gms:play-services-gcm:11.8.0") {
force = true
}
You'll have a much easier time controlling these conflicts by performing the following technique, as documented in the Android Developer Document Gradle Tips & Tricks (Another good explanation here). More and more, plugin authors are beginning to make their modules aware of application-wide configuration properties, just as this one.
In your application's "root" gradle file, define global properties to be used by your app and all the modules you include into it:
buildscript {...}
allprojects {...}
/**
* Project-wide configuration properties
*/
+ext {
+ compileSdkVersion = 26
+ targetSdkVersion = 26
+ buildToolsVersion = "26.0.2"
+ supportLibVersion = "26.1.0"
+ playServicesVersion = "11.8.0"
+}
In your app module's build.gradle
, implement your new Global Configuration Properties:
android {
+ compileSdkVersion rootProject.compileSdkVersion
+ buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion 16
+ targetSdkVersion rootProject.targetSdkVersion
.
.
.
}
}
dependencies {
+ compile "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
.
.
.
}