Long story shortened: I am changing an android app from using Azure mobile app services to use Google Firebase. Firebase was really easy and straight forward to get setup for Javascript but I have been having endless problems with getting Android setup.
My app has three modules: Full, Lite and a third module which acts as a library. I am trying to setup the app so that the full version has Firebase support and I did so using the assistant built into Android studio. After doing so this wouldn't build because the JSON file that was added only included the full version package name. I ended up creating 3 versions of the app in the Firebase console and manually adding the JSON file to the project (net.gptiming, net.gptiming.full and net.gptiming.library). This appears to have worked - I can use the Firebase libraries and the program built.
The next problem I found was that Firebase was failing to initialize - After several more hours of trawling Google and stackoverflow I found that this could be due to mismatched libraries. My initial step was to update Android studio (to 2.3.2) and the latest Google repositories and build tools.
Now this yielded yet another issue - One that I cannot seem to find anywhere online. Gradle will not sync due to the following error:
"Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension"
This error is showing in the library module gradle build file which contains the following:
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
buildToolsVersion '23.0.2'
}
dependencies {
compile 'com.google.code.gson:gson-parent:2.7'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
}
apply plugin: 'com.google.gms.google-services'
The project gradle file is as follows:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
}
}
ext {
compileSdkVersion = 19
buildToolsVersion = "23.0.2"
storeFilePath = System.getenv('STORE_FILE')
storePassword = System.getenv('STORE_PASSWORD')
keyAlias = System.getenv('KEY_ALIAS')
keyPassword = System.getenv('KEY_PASSWORD')
}
and here is the full version module file:
apply plugin: 'com.android.application'
dependencies {
compile project(':gptiming-gptiming')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
}
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
if (rootProject.storeFilePath) {
signingConfigs {
release {
storeFile file(rootProject.storeFilePath)
storePassword rootProject.storePassword
keyAlias rootProject.keyAlias
keyPassword rootProject.keyPassword
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
buildToolsVersion '25.0.0'
}
apply plugin: 'com.google.gms.google-services'
So far I have tried changing the Gradle version to 2.3 however Android studio 2.3.2 will not support the older Gradle version. I have also tried changing the build tools versions to the ones shown above which made no difference. Android studio offered no additional help on the problem.
Sorry for the long question but I am a rookie when it comes to Android development - I dont completely understand how the library aspect works with respect to Gradle and how to integrate Firebase correctly as the documentation is a little sparse and the built in tools are of no use. I do not know if the error has anything to do with Firebase or whether it is just a simple Gradle mismatch but any help would be much appreciated!
I should say that I had no problem with this library structure before updating the version of Android studio and the associated tools - however this could have been masked by the Firebase library issues. The app worked with Azure before these changes
I had the same problem with my library module and solved it updating gradle and google-services versions.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With