I set up a Firebase realtime database in an Android app, but I chose the wrong location, so I deleted the Firebase project. I then made a new project and did the exact same steps (yes, I did swap out the google-services.json file). However, when I try to access the database, through FirebaseDatabase.getInstance() for example, it still refers to the old project (which I can tell by the project id).
Also, when I do FirebaseApp.getApps(), it only contains the app with the "old" project id. After this didn't work, I did it all over again on a new branch, and it somehow still refers to the old project. I can see the correct project id in the google-services.json file, why is it not using it?
Project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath 'com.google.gms:google-services:4.3.4'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Relevant module gradle:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "test"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation platform('com.google.firebase:firebase-bom:26.1.1')
implementation 'com.google.firebase:firebase-database:19.6.0'
}
Just try out this simple solution..
remove the old google-services.json from your project.
uninstall previous version of your app in device/emulator.
place new google-services.json
clean and rebuilt before launching it to device.
hit run.
Related
After starting an android studio today, I came across a strange problem. It was saying
DSL element 'android.viewBinding.enabled' is obsolete and has been
replaced with 'android.buildFeatures.viewBinding'.
After searching for a bit I found out that I had to use
buildFeatures {viewBinding = true}
instead. So, I replaced viewBinding{enabled=true} with the above one. After that, the real problems started. AAPT can no longer detect my drawables. Here is my buildScript:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.techtrixbd.RestaurantApp"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {viewBinding = true}
}
I don't know what is going on anymore. Any advice will be a big help.
I have solved the issue. I had to move my resources to drawable-v24 folder. that's it. But, don't why it was required because everything was working fine yesterday. Maybe an update has something to do with it. I will look for the cause and will post if I come up with something.
i have some strange error / bug on android studio, my application gradle is complete and running smoothly on device but its showing error like my library is not completely include on android studio, i already do
Clean then Rebuild
Invalidate Cache and restart
but nothing work, this is the screenshot
This is My App Gradle
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.host.appname"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
useLibrary 'org.apache.http.legacy'
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
lintOptions {
disable 'MissingTranslation'
}
}
}
productFlavors {
}
packagingOptions {
exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
}
and this is my project gradle
buildscript {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
So i can run my application, i can use it but its really disturbing for me to do code because i cannot use autocomplete regarding the error libs and red marks everywhere .
Thank You..
Remove the lines and re-import them from correct/compatible packages.
Try removing all dependencies then sync and add all dependencies again then sync.
As you mentioned in comments nimi0112 and Ali Ahmed's your answer is really helped me a lot.
Since I updated my project on the new Android Studio 3.4 Canary 4, the gradle sync failed because:
ERROR: variant.getApplicationId() is not supported by feature plugins as it cannot handle delayed setting of the application ID. Please use getApplicationIdTextResource() instead.
Affected Modules: base
I was previously on Canary 3 and it worked perfectly.
The project is a multi feature app including an instant-app.
Gradle version is gradle-5.0-milestone-1-all
My project level build.gradle
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0-alpha04'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha07'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
compileSdkVersion = 28
minSdkVersion = 16
targetSdkVersion = 28
appVersionCode = 5
appVersion = "2.0.0-dev01"
}
base build.gradle
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'jacoco'
apply plugin: 'androidx.navigation.safeargs'
android {
def yo = rootProject
compileSdkVersion yo.compileSdkVersion
baseFeature true
defaultConfig {
minSdkVersion yo.minSdkVersion
targetSdkVersion yo.targetSdkVersion
versionCode yo.appVersionCode
versionName yo.appVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary true
multiDexEnabled true
}
buildTypes {
debug {
testCoverageEnabled !project.hasProperty('android.injected.invoked.from.ide')
multiDexKeepFile file('multidex-config.txt')
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
multiDexKeepFile file('multidex-config.txt')
}
}
dataBinding {
enabled = true
}
lintOptions {
disable "InvalidPackage"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
mavenCentral()
google()
}
dependencies {
application project(':app')
feature project(':module1')
[...]
}
app build.gradle
apply plugin: 'com.android.application'
android {
def yo = rootProject
compileSdkVersion yo.compileSdkVersion
defaultConfig {
applicationId "com.package.name"
minSdkVersion yo.minSdkVersion
targetSdkVersion yo.targetSdkVersion
versionCode yo.appVersionCode
versionName yo.appVersion
multiDexEnabled true
}
buildTypes {
debug {
applicationIdSuffix ".dev"
splits.abi.enable = false
splits.density.enable = false
aaptOptions.cruncherEnabled = false
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation project(':module1')
implementation project(':base')
implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.google.gms.google-services'
I tried to sync my project without dependencies but it doest work too.
I also tried to invalidate caches and restart but no effects.
According to the error log, the problem is in the base build.gradle file but I have no idea what is the problem.
Thank you in advance for your help!
Ok I founded the problem.
This is the safe args navigation plugin thats failed.
apply plugin: 'androidx.navigation.safeargs'
If I remove this line, the project is able to sync but not to build cause to classes missing from navigation safeargs.
There is a bug in the navigation plugin in Android Studio 3.4 Canary 4 applied in a baseFeature build.gradle file.
I will post a new question for that.
For anyone who have a similar issue make sure all dependencies in your project-level build.gradle are up-to-date.
For example, I had this issue when my version of google-services plugin was outdated:
buildscript {
repositories {
...
}
dependencies {
...
classpath 'com.google.gms:google-services:4.0.1'
}
}
After updating to the latest version the issue was resolved:
buildscript {
repositories {
...
}
dependencies {
...
classpath 'com.google.gms:google-services:4.2.0'
}
}
I'm trying to add Firebase Performance Monitoring to my Android Studio project. After I followed the steps on how to add it to my app, I cannot compile my app. This is the error:
Error:(1, 0) Unable to find method 'com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Project build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha7'
classpath 'com.google.gms:google-services:3.1.0'
classpath 'com.google.firebase:firebase-plugins:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
maven {
url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// Define versions in a single place
ext {
// Sdk and tools
minSdkVersion = 16
targetSdkVersion = 26
compileSdkVersion = 26
buildToolsVersion = '26.0.0'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
// Version
versionCode = 1;
versionName = "0.0.1";
...
// Firebase
firebaseVersion = '11.0.2'
...
}
App build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "REMOVED"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
dataBinding.enabled = true
}
compileOptions {
sourceCompatibility = rootProject.ext.sourceCompatibility
targetCompatibility = rootProject.ext.targetCompatibility
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
...
// Firebase
compile "com.google.firebase:firebase-core:$rootProject.firebaseVersion"
compile "com.google.firebase:firebase-perf:$rootProject.firebaseVersion"
...
}
apply plugin: 'com.google.gms.google-services'
You probably had firebase in your buildscript dependencies.
The problem was that I had firebase in my buildscript dependencies, so it looked something like this:
buildscript {
ext.kotlin_version = '1.1.3-2'
apply from: 'dependencies.gradle'
repositories {
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha6'
classpath ('com.google.firebase:firebase-plugins:1.1.0') //the firebase line
....
}
}
replacing the firebase classpath line with this:
classpath ('com.google.firebase:firebase-plugins:1.1.0') {
exclude group: 'com.google.guava', module: 'guava-jdk5'
}
Then you have to clean the project, kill the gradle daemon and restart android studio.
Unable to find method (can't compile project) after gradle update
I'm having a lot of trouble adding databinding to my project. There is a complicated build.gradle. Unfortunately, I cannot post too much from it.
If I add databinding {enabled = true} to my android block in my app build.gradle file I get the following error -->
Error:Cannot change dependencies of configuration ':projectName:compile' after it has been resolved.
Cannot get property 'javaCompile' on null object.
I've added the databinding library on my classpath. If I don't add the dataBinding {enabled = true} block the build succeeds with a warning that generated sources are in the wrong folder.
Any ideas?
Here is my sample build.gradle with databinding enabled. I'm using this setup in my projects and databinding is working fine. Notice that you only need to specify databinding {enabled true}. No more setup is required. You don't have to add databinding to dependencies.
build.gradle from main folder
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
subprojects {
buildscript {
repositories {
jcenter()
mavenCentral()
}
}
repositories {
jcenter()
mavenCentral()
}
}
build.gradle from app
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "foo.bar"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//support library
compile 'com.android.support:appcompat-v7:23.1.1'
}