Android App with Google Drive API stucks after choosing an account. Why? - android

I'm trying to understand how I can integrate Google Drive API in my Android App(using Android Studio). I have tried the example app that I found here(https://github.com/googleworkspace/android-samples/tree/master/drive/deprecation) but after Google API console configuration my app stucks in an infinite loop when I choose an Account. Why? Where is the problem?
I tried also with this(https://youtu.be/5bSEIQYJzKs) tutorial but I have the same problem.
Here my build.gradle specific lines:
implementation "androidx.multidex:multidex:2.0.1"
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation ('com.google.apis:google-api-services-drive:v3-rev136-1.25.0')
{
exclude group: 'org.apache.httpcomponents'
}
implementation ('com.google.api-client:google-api-client-android:1.26.0')
{
exclude group: 'org.apache.httpcomponents'
}
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
and here is the version that I use
compileSdkVersion 30
buildToolsVersion "30.0.3"
The problem is in this code lines, and occurs only if I use ".requestScopes(new Scope(DriveScopes.DRIVE_FILE))":
if i donot use .requestScopes(new Scope(DriveScopes.DRIVE_FILE))", then code works fine. and user do get logedin
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(DriveScopes.DRIVE_FILE))
.requestEmail()
.build();
GoogleSignInClient client= GoogleSignIn.getClient(this,signInOptions);
Intent i= client.getSignInIntent();
startActivityForResult(i,400);
(it seems like the activity never returns any value).
Without ".requestScopes(new Scope(DriveScopes.DRIVE_FILE))" the auth request is successful.
Here my Google console configuration:
The client ID
(sorry, maybe it will appear as a link but stackOverflow tell me that I can't put img)
and
".../auth/drive.file" is the authorization that I request in google Consent window that appears to the user.
I don't know if it is important to say but I use a real phone and not the Android Studio emulator to test my app.

I just solved it. For all those who encounter this problem: from the Google API console, remove the consent screen from the test state and publish it.

Take a look at https://issuetracker.google.com/issues/178183308 where the issue was reported to Google.

Related

Android FirebaseMessaging - getToken fails for some users

I have the following setup in my grade files:
project:
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
app:
implementation platform('com.google.firebase:firebase-bom:29.0.0')
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging'
After the users logs in, I'm doing
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(task -> {
String refreshToken = task.getResult();
....
}
which is fine for most users, but for some (not only a few) get errors like FIS_AUTH_ERROR, MISSING_INSTANCEID_SERVICE, SERVICE_NOT_AVAILABLE.
I guess (!), MISSING_INSTANCEID_SERVICE is no Google API on the device, SERVICE_NOT_AVAILABLE missing network (?) but I'm not sure at all. And I have absolutely no clue about the FIS_AUTH_ERROR. Is there some documentation about this?
MISSING_INSTANCEID_SERVICE
Tokens can't be generated.
SERVICE_NOT_AVAILABLE
The device cannot read the response, or there was a server error.
FIS_AUTH_ERROR
you need to check the documentation get token and get id methods had changed
I think it has to do with firebase dependencies versions mismatch. Try to import the BoM for the Firebase platform. By using BoM your app will always use compatible versions of the Firebase Android libraries.
dependencies {
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:30.0.2')
// .... }
FIS_AUTH_ERROR suggests, that the local installation cannot be authenticated:
Firebase Cloud Messaging uses Firebase installation IDs to target devices for message delivery.
Source: Manage Firebase installations
It's a little difficult, unless having a device available, which would show this issue - or somehow being able to narrow this down - by hardware vendor, Android version or package version - because "some (not only a few)" is relatively meaningless, from a technical perspective.
It could well be, that the SHA1/SHA265 key fingerprint might have been changed (you should know) and "some (not only a few)" might still haven't updated to the latest version of the APK/AAB package, signed with the new signing key. Crashlytics would show the package version. You could add the old SHA1/SHA265 key fingerprint back in, so that their instances could authenticate again.

NoClassDefFoundError dependency issues calling Gmail API

I'm trying to access my Gmail from an Android app and am running into dependency issues. I've been following a combination of guides, including the Java Quickstart (https://developers.google.com/gmail/api/quickstart/java) and a few others on StackOverflow and GitHub.
Whenever I run the emulator, I get a "NoClassDefFoundError", always from a Google API call to AuthorizationCodeInstalledApp.authorize(). Here's one of them:
java.lang.NoClassDefFoundError: Failed resolution of: Lsun/security/action/GetLongAction;
at sun.net.httpserver.ServerConfig.<clinit>(ServerConfig.java:43)
at sun.net.httpserver.ServerConfig.getClockTick(ServerConfig.java:100)
at sun.net.httpserver.ServerImpl.<clinit>(ServerImpl.java:50)
at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:32)
at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:17)
at com.sun.net.httpserver.HttpServer.create(HttpServer.java:111)
at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver.getRedirectUri(LocalServerReceiver.java:127)
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:108)
at com.example.gmailtemplates.ui.templates.TemplateListAdapter.getCredentials(TemplateListAdapter.java:141)
Here's my code that calls it, which I literally copied and pasted from a guide:
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(tokenFolder))
.setAccessType("offline")
.build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
return credential;
My gradle build file includes:
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.api-client:google-api-client:1.32.2'
implementation 'com.google.oauth-client:google-oauth-client-jetty:1.32.1'
implementation 'com.google.apis:google-api-services-gmail:v1-rev20211108-1.32.1'
implementation 'com.google.android.gms:play-services-auth:20.0.0'
....
}
The thing is that I'm pretty sure that sun.net.httpserver is pretty old and no longer used. Am I missing something or using some weird old version of Google API? I'm using Android Studio for the first time, so it's possible that I made some wrong configuration.

Okhttp stops working after updating android studio

I've an Android app using retrofit 2 and okhttp for its json requests. everything was going fine until android studio(AS) oferred me the update from 3.9.6 to 4.1
The update is done easily inside the AS and it also updates the gradle plugin.
Once the update was finished I rebuild and compiled a new aab, then i notice the new file generated was 100kb smaller than the previous one (altough no code or assets changes were made, only the IDE version updated)... then i release on google play and download it in my test device (real phone). It didn't work. The app opens but it is not able to perform any okhttp request
I tried to run inside AS emulator -> it worked fine.
I tried to run in the emulator with minifyEnabled true shrinkResources true -> it worked fine
so i added to the code several debug calls in order to let me know exaclty until what line the app was working.... and i got.
try {
okHttpClient.newCall(new Request.Builder().get().url("https://www.google.com").build()).execute();
return true;
} catch (Exception e) {
return false;
}
this is a little snippet i use to test if user has internet connection.
No exception is thrown, no value is returned, the call simple dive into the okhttp api and never come back...
So i want to let clear: no code was changed, no api was updated, no r8 rules was changed
the only thing changed was the AS updated from 3.9.6 to 4.1 and some mandatory gradle plugin updated as well
after that the signed aab built got 100kb smaller and this very weird behavior started happening...
I've already tried EVERYTHING i can, but still no idea how to solve. does anyone ever face a similar problem or have idea what to do?
there are my imports
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation('com.facebook.android:facebook-login:5.13.0') {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
//retrofit
implementation('com.squareup.retrofit2:retrofit:2.9.0') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
implementation "com.squareup.okhttp3:okhttp:4.10.0-RC1"
implementation 'com.squareup.okio:okio:2.9.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation('com.squareup.retrofit2:converter-gson:2.9.0') {
exclude group: "com.google.code.gson", module: "gson"
}
I've already tried EVERYTHING i can, but still no idea how to solve. does anyone ever face a similar problem or have idea what to do?
Yes, everyone faces these problems. It's part of the learning process of being a developer. Stop focusing on this particular problem with this library for a minute and ask why you are stuck and how to get unstuck. If you reported this to a library maintainer this is what they would need to do, which is why they would ask for a clean reproduction.
Firstly read http://sscce.org/ and understand what it means and why the above question isn't getting answers. It's not a clean reproduction, it's a few random lines of code.
Then ask a a colleague to help you use a debugger, where is it stuck, what are the threads doing or waiting on.
Use the features of the library e.g. add an OkHttp Event Listener https://square.github.io/okhttp/events/.
Going back the SSCCE example, make a small example project reproducing the issue and post it to a temporary github project, then report that as a bug to OkHttp project. They can just check out the project and run it to reproduce then.
For me, I was trying to fetch data using a retrofit. Getting 400 on release build. My model was like the following:
data class ContentIdAddRQ(
#SerializedName("contentId")
val contentId: String? = null,
#SerializedName("contentType")
val contentType: String? = "VOD",
)
Then I tried adding #Keep annotation to my Model file as shown below:
#Keep
data class ContentIdAddRQ(
#SerializedName("contentId")
val contentId: String? = null,
#SerializedName("contentType")
val contentType: String? = "VOD",
)

Google Fabric: UiAutomation not connected

After deployment of an app to Google Play Beta I see next issue in Crashlytics (6 - 7 users are affected)
Fatal Exception: java.lang.IllegalStateException: UiAutomation not connected!
at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:971)
at android.app.UiAutomation.disconnect(UiAutomation.java:237)
at android.app.Instrumentation.finish(Instrumentation.java:222)
at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:351)
at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:405)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:394)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1960)
It seems that it's google test devices.
Any ideas about fix?
It seems like nothing to worry about (don't rely on accepted answer and don't remove your tests) because crashes have been reported on creating pre-launch report for google play store where some UI automation tests were executed. If you track devices on which this error has occurred then you'll see that all paths lead to pre-launch report.
You can find out more about pre-launch report here
It seems that this crash is related to UI testing in your app. If you don't have any UI testing and there are only default settings which added automatically during creating the project, you should remove from your build.gradle the line testInstrumentationRunner in defaultConfig
defaultConfig {
....
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
and androidTestCompile, testCompile in dependencies
dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
...
One thing is sure: you have an issue on UI. In most cases this occurs when you show a progress dialog that keeps being displayed for too much time. In this case the Google crawler goes in timeout and raises an exception.
My advice is: be sure to not block UI with infinite dialogs.
The funny thing is that I get this crash while my app is being tested by google before publishing. I really don't know what google team is doing.

FirebaseCloudMessaging : FirebaseInstanceId background sync failed - SERVICE_NOT_AVAILABLE

I have use Firebase Cloud Messaging(FCM) API for the push notification in Android. When I implemented that time perfect work but now it's can not find the Service of google play.
the error is:
FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE,
Please help me how to resolve. I Have use below dependency in gradle file.
dependencies {
compile files('libs/ksoap2-android-assembly-3.4.0-jar.jar')
compile 'com.android.support:appcompat-v7:23.0.0'
compile files('libs/gson-2.2.4.jar')
compile files('libs/activation.jar')
compile files('libs/mail.jar')
compile files('libs/additionnal.jar')
compile 'com.android.support:multidex:1.0.1'
compile 'com.facebook.android:facebook-android-sdk:4.14.0'
compile 'com.google.firebase:firebase-messaging:9.0.2'
compile('com.google.android.gms:play-services:9.0.2') {
exclude group: "play-services-wallet"
exclude module: "play-services-wallet"
exclude group: "play-services-ads"
exclude module: "play-services-ads"
}
}
Thanks for taking the time to read this.
Verify internet connectivity
Verify if the Android SDK tools(Tools -> Android -> SDK manager -> SDK tools tab) has 'Google Play services' latest version and if not install the package.
Then if you are using emulator, please stop the emulator and start it again.It works
You can check
Check your internet connection with no proxy and open internet connect
Replace your google-service.json with new one you can get this in firebaseconsol
Please check your device has google play service in it and it working or not , firebase not work without google play service
Check -FireBaseInstanceId service does not get registered
After long struggle i found the answer, if google play service is not running then FirebaseInstanceId background sync failed - SERVICE_NOT_AVAILABLE log print, so you can check your google play service is running properly or not ?
May be this information is helpful to you !
the service needs to be bound in the Manifest.xml
<!-- Firebase InstanceId Service -->
<service
android:name="eu.acme.service.FireBaseInstanceIdService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
then one can access one single exposed method (the other names are obfuscated = not reliable):
package eu.acme.service;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class FireBaseInstanceIdService extends FirebaseInstanceIdService {
#Override
#android.support.annotation.WorkerThread
public void onTokenRefresh() {
/* obtain the current InstanceId token: */
String token = FirebaseInstanceId.getInstance().getToken();
}
}
one could only work around it, by not provoking it, eg. by not adding any AuthState Listener while knowing that there is no active network present, as explained here - as it seems, one otherwise cannot catch the exception thrown from within the library - which can be ignored, since it merely just complains, that there is no network connectivity.
com.google.android.gms.iid and com.google.firebase.iid are about the same.
I had to disbale my VPN - hope this helps someone !
I just had this problem. In my case, only worked when I stopped the emulator, closed it, and opened again. I didn't make any other changes.
Easiest solution is to delete the bin and obj folders under the .Droid directory.
In this way you have a clean start every time.
In my case - I rebooted my PC and it worked.
Im not an expert, so I might have covered one of the mentioned tipps by my approach
Connect your mobile with different wifi connection with different service provider. It seems weird but you can try it!
In my case, I just removed instant run from Android Studio preferences
Me too had the same issue, resolved by just Clean Project option under build. Hope it might help anyone here.
You need to update your play services and make sure your internet connectivity is good.
In my case
I have been Added google-services.json file in Project root, I moved it to app folder and problem has been fixed.
MyProjectRootDir/google-services.json
move to -->
MyProjectRootDir/app/google-services.json

Categories

Resources