I am trying to set up the Firstore API with my Android project however when I try to call FirebaseFirestore.getInstance() I get this error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.google.firebase.FirebaseApp.<clinit>(com.google.firebase:firebase-common##16.1.0:150)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore##18.1.0:70)
at ip.travelaid.backend.Database.<init>(Database.java:16)
at ip.travelaid.backend.CLITest.main(CLITest.java:11)
Caused by: java.lang.RuntimeException: Stub!
at android.os.Looper.getMainLooper(Looper.java:23)
at com.google.firebase.FirebaseApp$UiExecutor.<clinit>(com.google.firebase:firebase-common##16.1.0:987)
... 4 more
I have checked both my project and app level build.gradle files and they match what the documentation requires, even the Firebase Assistant in AS says that they are right. Just in case though here they are:
Module build.gradle:
// 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.3.2'
classpath 'com.google.gms:google-services:4.2.0'
// 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
}
App build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "ip.travelaid"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.google.firebase:firebase-firestore:18.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
In the Firebase Console I have set up the database to deny any read/write requests but I thought that wouldn't affect my ability to get an instance to the database.
The google-services.json file for the Firebase project is up to date, I have even tried re-downloading it from the Firebase Console to no avail.
I have tried searching for a solution online but there seem to be nothing out there on it(this could well be down to me not being able to search for the issue properly though).
Is there a setting, either in the Firebase Console or AS, that I am missing that may be causing this issue?
update compiled & target sdk like so v
compiled sdk 26
to
compiled sdk 28
Obligatory: NVM I figured it out.
The problem was that I tried to run the code from the command line and not through an Android Emulator/Device actually running the app.
When I did run it there the problem disappeared.
Related
I'm trying to compile an Android app and the Gradle build is failing. The project is in Java but does have Room code as well, which I believe is where the issue is arising from. The build is unable to find the Guava repository at www.google.com:guava:23.6-Android even though this file has been added as a dependency.
The initial result build fail looks like this:
Could not find com.google.guava:guava:23.6-android.
Required by:
project :App
The project-level build file:
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The app level build file contains the following:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.nathan.digipizza"
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
dataBinding true
}
}
dependencies {
implementation 'com.google.guava:guava:26.3-android'
def room_version = "2.3.0"
implementation 'androidx.appcompat:appcompat:1.4.0-rc01'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.5.0-alpha05'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-compiler:2.4.0'
implementation 'androidx.room:room-runtime:2.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
annotationProcessor 'androidx.room:room-compiler:2.3.0'
}
It is difficult to post the entire dependency tree since I'm still unable to post screen images. But the repository in question, com.google.guava:guava:23.6-android, is not listed as a dependency for any other files, and its entry in the tree for the release variant reflects this fact as it is situated furthest left on the tree as follows:
+--- com.google.guava:guava:23.6-android FAILED
This repository only appears once in the dependency tree, furthermost to the left.
The com.google.guava:guava:23.6-android repository has an updated version to 30.1-android. I did update the version, but the error remains and everything is the same as above except version 30.1-android replaces version 23.6-android.
I need to figure out how to resolve the build error, which I'll post here again for ease of use:
Could not find com.google.guava:guava:23.6-android.
Required by:
project :app
I don't understand how the build is failing to see this repository when it has been added as a dependency, and there doesn't appear to be any complications apparent by analyzing the dependency tree.
I'm really frustrated. I'm new to Android development and Gradle. Last week I was able to download Android Studio and created a simple app that contains a few buttons. I had no trouble creating and running this.
This week I decided to create another, simpler app with no activities, to check whether my environment is set up properly. After a couple of days, I cannot get the IDE to build the app, and the problems appear to be Gradle-related.
Here is my gradle-wrapper.properties file:
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Here is my app-level build.gradle file:
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 16
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
And here is the top-level gradle.build file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
// 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
}
I read up on additional repositories that are needed, and tried inserting this code into the top-level Gradle build file:
repositories {
google()
jcenter()
maven { url "https://www.jitpack.io" }
}
}
But this does not help. When I try to build the project, I get errors saying that Gradle cannot find files (if I check the "offline" option) or when online, I see errors like this:
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ':classpath'
In Settings, I have "Auto-detect proxy settings" checked (I'm not behind a firewall), and I'm using Gradle from the gradle-wrapper.properties file.
Given that I'm able to rebuild the app I created last week, but cannot build this new app whatever I try, I'm wondering whether file caching might be causing this trouble. I did try deleting the cached Gradle files from .gradle (I'm running on Windows 10) but that did not help. Multiple times, I have tried invalidating the cache and restarting the IDE but this does not make a difference.
I recently began using Android Studio and was trying to follow the "First App" tutorial (https://developer.android.com/training/basics/firstapp/). When I create a new project in Android Studio, however, I am almost immediately greeted by this error
ERROR: Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-5.4.1-all.zip'.
I've tried deleting my ~/.gradle directory and invalidating caches before restarting android studio but this doesn't fix the issue. I've also tried downloading gradle and using a local distribution of it, as well as playing with the version both locally and the default gradle wrapper version found in the cradle-wrapper.properties file. I tried both using the most current distribution (6.0.1) as well as going back a few versions and nothing has helped.
I am running on Mac OS 10.13.6 and Android Studio 3.5.2, using a Nougat distribution for my project (API 24, Android 7.0).
Edit: When I open the event logger, this is what I see:
11:18 Gradle sync started with single-variant sync
11:18 Gradle sync failed: ch.qos.logback.classic.Logger cannot be cast to org.gradle.api.logging.Logger (2 s 7 ms)
11:18 NDK Resolution Outcome: Project settings: Gradle model version=5.4.1, NDK version is UNKNOWN
Edit:
build.gradle files
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "eecs285.proj4.nortoncofirstapp"
minSdkVersion 24
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
// 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.5.2'
// 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
}
I registered to admob about 24 hours ago. Confirmation mail come from admob. I added admob id's to my app. When i install my app to a real device by clicking run button in android studio, the real ads showing properly. So my admob ids work correctly.
However, when i generate signed apk and install the apk to my device by apk install ... command using Android Studio terminal, real ads does not showing. I firstly think that the problem is related to proguard however it is not related to proguard. Because i deactivated proguard and the real ads still not showing. What may be the problem?
build.gradle (app level):
apply plugin: 'com.android.application'
apply plugin: 'com.bugsnag.android.gradle'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "...."
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'jp.wasabeef:recyclerview-animators:2.2.4'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.nex3z:flow-layout:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-ads:17.1.1'
implementation 'com.bugsnag:bugsnag-android:4.+'
}
build.gradle(project level)
// 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.2.1'
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:3.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Check your logcat, if you are getting W/Ads: Failed to load ad: 3 warning it means that the ad request was successful, but no ad was returned due to lack of ad inventory so your code is OK! You just need to wait a couple of days and the ads will appear.
I had a similar issue with my app, I published it as beta on Google Play on 5 dec then the full release on 19 dec and ads started to show only today!
I want to use OneSignal in my android app but I get some errors after adding OneSignal dependency in my gradle file.
I am using Android Studio 3.1.
This is my gradle file:
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.nasser.myapplication"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
postprocessing {
removeUnusedCode false
removeUnusedResources false
obfuscate false
optimizeCode false
proguardFile 'proguard-rules.pro'
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso- core:2.2.2'
compile 'com.onesignal:OneSignal:[3.6.2, 3.99.99]'
}
and this is project's build.gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha01'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
now when i sync gradle file i get many errors like this one:
Could not resolve com.android.support:support-v4:[26.0.0,26.2.0).
Required by:
project :app > com.onesignal:OneSignal:3.6.5
> Could not resolve com.android.support:support-v4:[26.0.0,26.2.0).
> Failed to list versions for com.android.support:support-v4.
> Unable to load Maven meta-data from https://dl.google.com/dl/android/maven2/com/android/support/support-v4/maven-metadata.xml.
> Could not HEAD 'https://dl.google.com/dl/android/maven2/com/android/support/support-v4/maven-metadata.xml'.
> dl.google.com:443 failed to respond
You should add the google maven in your project build.gradle:
repositories {
maven { url 'https://maven.google.com' }
}
You need to remember that OneSignal automatically adds the following dependencies:
com.google.android.gms - Version 11.2.+
com.android.support - Version 26.1.+
So, all dependencies must have matching versions.
To force the support library which your selected version, you can use the following:
// Must use 26.0.0 or newer if you have targetSdkVersion 26
def androidSupportVersion = '26.1.+'
compile("com.android.support:support-v4:${androidSupportVersion}") {
force = true
}
compile("com.android.support:customtabs:${androidSupportVersion}") {
force = true
}
Read more at Troubleshooting Android.
p.s: You should fix your build.gradle.
I met the same problem in Android Studio 3.1, and all build tasks are failed.
Finally I found my problem is caused by Gradle proxy setting. The solution:
Open the file ~/.gradle/gradle.properties, and delete proxy settings in it if any, like
systemProp.https.proxyPort=50846
systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=50846
then restart Android Studio, build tasks works now.