I'm trying to create a game with firebase google and facebook login. I know that it is possible to use firebase with unity, but I don't want to create both login methods separately, when something like FirebaseUI exists.
So I've created android plugin with FirebaseUI authentication. I tested it in new android project and everything works fine. But when I use my plugin in unity, I have to add my own gradle (mainTemplate.gradle) with dependencies for firebaseUI.
Problem is that there is a default value in firebase auth library and when the game is built, values from my library (default_web_client_id etc.) is overwritten by default value.
Almost after week I found a solution, but I hope there is another way.
My solution: Build android library with firebase, copy library (.aar) to Assets/Plugins, export unity project with this library to Idea, then copy the entire file values.xml (that is created from google-services.json) and facebook appId to res folder in exported project. (then build from Idea)
It's working, but by this method, I have default_web_client_id 3 times in project (1x from my library, 1x from FirebaseUI dependency and 1x from copied values.xml, that overrides them). It's not a problem, but I think that it's not necessary.
Is there any more elegant way to work with firebaseUI and android libraries?
mainTemplate (dependency part):
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
implementation 'com.facebook.android:facebook-android-sdk:4.41.0'
**DEPS**}
after some more experiments I found that it depends on implementation order, so I moved **DEPS** up and now its working.
So the solution is easy:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
**DEPS**
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
implementation 'com.facebook.android:facebook-android-sdk:4.41.0'
}
Hope that this helps somebody.
Related
Am trying to load Interstitial Ad on click of a button. unfortunately, getting this.
java.lang.IllegalArgumentException: Service not registered: com.google.android.gms.measurement.internal.zzjl#f5ae32b
at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1757)
app build.gradle
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.2.0'
implementation 'com.google.firebase:firebase-core:18.0.0'
implementation 'io.github.kobakei:ratethisapp:1.2.0'
implementation 'com.google.android.gms:play-services-ads:19.6.0'
implementation 'com.google.firebase:firebase-perf'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
implementation 'com.github.hotchemi:android-rate:1.0.1'
project build.gradle
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
classpath 'com.google.firebase:perf-plugin:1.3.4'
If you're going to use the Firebase BoM, you should set it set the versions of all Firebase dependencies. Your are not letting it the version of this:
implementation 'com.google.firebase:firebase-core:18.0.0'
In fact, you shouldn't need firebase-core at all any more. According to the documentation:
The Firebase Android library firebase-core is no longer needed. This SDK included the Firebase SDK for Google Analytics.
So, just remove the dependency entirely if you aren't using it directly. Or at least remove the version number.
If you don't use analytics, try remove this line:
implementation 'com.google.firebase:firebase-analytics'
I am getting error in the whole class that extends BottomSheetDialogFragment
Cannot access 'androidx.lifecycle.HasDefaultViewModelProviderFactory' which is a supertype of 'FavoriteBottomDialogFragment'. Check your module classpath for missing or conflicting dependencies
The class is in app module and this module implements two other modules : core and presentation-core
build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project (':core')
implementation project (':presentation-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
testImplementation 'junit:junit:4.12'
implementation "com.google.android.material:material:1.1.0"
//Rx
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
implementation "io.reactivex.rxjava2:rxjava:2.2.9"
//Architecture component
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.room:room-runtime:2.0.0'
kapt 'androidx.room:room-compiler:2.0.0'
kapt 'androidx.lifecycle:lifecycle-common-java8:2.0.0'
implementation 'androidx.room:room-rxjava2:2.0.0'
implementation 'androidx.room:room-guava:2.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
}
core dependencies
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4"
api 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
//library to serialize Java Objects between Contexts
implementation 'org.parceler:parceler-api:1.1.11'
kapt 'org.parceler:parceler:1.1.11'
//testing dependencies
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation "org.mockito:mockito-core:2.24.5"
androidTestImplementation "org.mockito:mockito-android:2.24.5"
//architecture component
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
implementation "androidx.lifecycle:lifecycle-livedata:2.0.0"
//RxJava2
implementation "io.reactivex.rxjava2:rxjava:2.2.9"
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
}
presentation-core
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
}
BottomSheetDialogFragment
Even with errors i got, I can run the project in a device
I experienced this exact same problem today, and was able to solve.
Turns out the issue was a version mismatch between the expected version of androidx.lifecycle:lifecycle-viewmodel used by the module where the "failing" class is and a later version in some other dependent code.
So in my case, my module was using version 2.1.0 of this module, but one of the dependencies was using version 2.2.0. The code will compile no problem, because gradle resolves the dependency to the latest version; however Android Studio is somehow confused by this situation (not always, because this doesn't happen all the time, but sometimes – this isn't the first time I've seen this.)
Therefore solution is: figure out what the latest version of this library is in your app and update your build.gradle for this module to point to the same version that gradle is resolving to. Or:
run gradlew app:dependencies
search the result for lifecycle-viewmodel
update build.gradle in your app to depend on lifecycle-viewmodel with the version that gradle says it is resolving to
Sync project with gradle files
in my case (an Android module), Android Studio 4.0.1, I get a number of warnings in the IDE related to androidx.lifecycle.HasDefaultViewModelProviderFactory,
I have solved the issue by adding this line to build.gradle:
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
thus the beginning of build.gradle becomes:
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
...
In my case, the problem was solved adding the lifecycle viewmodel dependency in the module of the troubled class.
Add dependency into you build gradle androidx.fragment:fragment-ktx:x.x.x with actual version. For activity you must add androidx.activity:activity-ktx:x.x.x. I hope this helps you, in my case it solved the problem.
I added the following lines to build.gradle to solve the same issue in a module:
def archLifecycleVersion = '2.2.0'
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
kapt "androidx.lifecycle:lifecycle-compiler:$archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
Your androidx.lifecycle:lifecycle-XXX dependency versions must be the same.
in my case:
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
Tried to add Firebase UI implementation
implementation 'com.firebaseui:firebase-ui-database:6.2.0'
in build.gradle file.
The following error was shown.
*ERROR: Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.firebaseui:firebase-ui-database:6.2.0.
Affected Modules: app*
Please guide me how to resolve the issue.
I am using Android Studio 3.5.3
Other dependencies I have already implemented in the app
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.4'
You need to update the following dependencies:
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.4'
to
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-database:19.2.0
Also upgrade to androidX. Check the following for more information:
From the docs:
FirebaseUI version 6.0.0 has no breaking API changes from version 5.1.0 but updates critical dependencies to new major versions.
There are two major groups of changes:
Convert all Android Support Library dependencies to AndroidX or Jetpack dependencies. For information on migrating to AndroidX see this guide.
Update all Firebase and Google Play services dependencies to their latest major versions. For information on changes included in these SDKs visit the release notes.
You can follow these steps:
Press F4 to open Module settings
Select Dependency
Click Add new dependency
Type firebase, search for firebase.ui and add its latest dependency.
At last I was able to sync successfully without Error.
The final dependencies in the build.gradle file of the app.
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.firebaseui:firebase-ui-database:6.2.0'
I need to use a different set of firebase libraries in the project. But I'm getting the following error :
Unable to resolve dependency for ':#debug/compileClasspath': Could not resolve com.android.support:support-v13:28.0.0.
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.android.gms:play-services-plus:17.0.0'
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.firebase:firebase-messaging:19.0.0'
// Add dependency
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.firebase:firebase-iid:19.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation 'com.google.firebase:firebase-crash:16.2.1'
If you want to use the latest versions, then you can use firebase BoM, in the build.gradle, write the following:
dependencies {
// Import the platform
implementation platform('com.google.firebase:firebase-bom:20.0.1')
// When using a BoM, dependencies don't require a specified version
// If you do specify a version, it overrides the library version specified in the BoM
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
}
com.google.firebase:firebase-bom:20.0.1 will contain the latest version of all firebase libraries, then to use each specific library you add them as you normally do but without a version.
References:
https://firebase.google.com/docs/android/setup#firebase-bom
I had an Android project with gradle 2.2.0 and android-apt plugin 1.8. I had time to update it to newer tools gradle 3.1.0 and remove apt plugin to use newer proposed solution with implementation/CompileOnly and annotation processor keywords. After that project build/compile correctly and apk file is pushed to device but when I open class that uses: butterknife, tourguide, FancyToast or material-dialogs libraries class not see this dependencies (imports & references are marked in red).
Did anyone had the same issue?
Current dependencies:
dependencies {
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
annotationProcessor "org.projectlombok:lombok:1.16.12"
compileOnly "org.projectlombok:lombok:1.16.12"
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation ('com.github.worker8:tourguide:1.0.14-SNAPSHOT#aar') {
transitive = true;
}
implementation files('libs/greendao-2.1.0.jar')
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
//dagger
compileOnly 'javax.annotation:jsr250-api:1.0'
implementation 'com.google.dagger:dagger:2.0.2'
annotationProcessor 'com.google.dagger:dagger-compiler:2.0.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.2#aar') {
transitive = true;
}
//save player objects (protect from removing it)
implementation 'com.google.code.gson:gson:2.7'
//permutation library
implementation 'com.googlecode.combinatoricslib:combinatoricslib:2.1'
//new toasts
implementation 'com.github.Shashank02051997:FancyToast-Android:0.1.3'
//tests
testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-core:2.+"}
Project compiles/works but it is obstacle to work with this libraries
If your dependencies declared in different module you should use api instead of implementation
eg:
api 'com.google.dagger:dagger:2.0.2'