Hello I am currently migrating the android part of my cordova/phonegap app from ant to gradle, and I am trying to add the fabric SDK.
In cordova projects the build.gradle seems to be autogenerated, and all changes should be added to the build-extras.gradle. How can I add additional dependencies in the buildscript block?
This is how the stuff for fabric should look in build.gradle, and it works if I put it here, but it is overwritten.
buildscript {
repositories {
mavenCentral()
// this line needs to be added
maven { url 'https://maven.fabric.io/public' }
}
// this block needs to be added
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
If I add this block in the build-extras.gradle, Groovy complains with
Failed to apply plugin [id 'io.fabric'] Plugin with id 'io.fabric' not found.
but if I add it into the build.gradle it might get overridden and will not be added to my colleagues builds (there is a warning at the top of the file that it should not be edited).
My build-extras.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
android {
dependencies {
compile('com.facebook.android:facebook-android-sdk:3.21.1') {
exclude module: 'support-v4'
}
compile 'com.google.android.gms:play-services:7.5.0'
}
// dexOptions {
// preDexLibraries = false
// }
}
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// Crashlytics Kit
compile('com.crashlytics.sdk.android:crashlytics:2.3.2@aar') {
transitive = true
}
}
I am pretty new to Gradle ... in the build.gradle there is this line ... maybe it can help me?
// Allow plugins to declare Maven dependencies via build-extras.gradle.
repositories {
mavenCentral()
}
To solve the problem I am currently using a before_build cordova hook that overrides the build.gradle and my MainActivity.java with my own custom version stored in a non platform folder in my cordova project repository.
The modified MainActivity.java just has this extra line added after loadUrl(launchUrl);
Here is the Cordova hook.
In the build.gradle you just need to add this after the buildscript {
And in build-extras.gradle, in the last dependencies block
This is not a final solution, and only a very hacky way to make it work. It might break on cordova updates.
I will answer again if I find a better solution. This bash scripts will work if you have a Linux and maybe if you have a Mac system.