Skip to content

Commit dc164a4

Browse files
committed
merge: Drive sign-in diagnostics
2 parents 8a32380 + 183e0b0 commit dc164a4

3 files changed

Lines changed: 71 additions & 4 deletions

File tree

docs/guides/google-drive-sync.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,34 @@ package/signature pair and is not passed through `--dart-define`. Android also
6464
uses the Web client ID created above as its server client ID.
6565

6666
For the debug fingerprint, run `./gradlew signingReport` from `android/` (or
67-
`gradlew.bat signingReport` on Windows). Configure a real release signing key
68-
before publishing; the current project release build still uses the debug key.
67+
`gradlew.bat signingReport` on Windows).
68+
69+
For the release fingerprint, read it from the keystore itself:
70+
71+
```powershell
72+
keytool -list -v -keystore admincraft-release.jks -alias admincraft
73+
```
74+
75+
!!! warning "Changing the signing key breaks Drive sign-in"
76+
77+
Google identifies an Android app by package name **and** signing
78+
certificate. A build signed with a different key than the registered
79+
Android client matches nothing, and sign-in fails with
80+
`[16] Account reauth failed` even though the client IDs are correct.
81+
Registering a release key after shipping debug-signed builds, as this
82+
project did in v2.2.0, is exactly that situation: the release fingerprint
83+
needs its own Android client.
84+
85+
The fingerprint of an already published build can be read from the APK
86+
itself, which is worth doing to confirm what actually shipped:
87+
88+
```powershell
89+
apksigner verify --print-certs admincraft-v2.2.0-android.apk
90+
```
91+
92+
`apksigner` comes with the Android SDK build-tools. `keytool -printcert
93+
-jarfile` will not do here: it reads only v1 JAR signatures, and these
94+
APKs are signed with the v2/v3 schemes alone.
6995

7096
#### Windows client
7197

@@ -139,3 +165,18 @@ for explicit recovery.
139165
!!! warning
140166
Google cannot recover the encryption passphrase. Keep a manual exported
141167
backup somewhere safe before relying on sync alone.
168+
169+
## When sign-in fails
170+
171+
| What the app says | What it usually means |
172+
| --- | --- |
173+
| This build is not registered in its Google Cloud project | No Android OAuth client matches this package name and signing certificate. Register the fingerprint of the build you are running, as above. |
174+
| Setup required | The build carries no client IDs. They are compiled in, so a build made without them cannot sign in at all; check the repository secrets and rebuild. |
175+
| Sign-in was cancelled | The account chooser was dismissed. |
176+
177+
Two things that look like app faults and are not:
178+
179+
- The account must be listed under **Test users** while the Google Auth
180+
Platform app is in testing. Any other account is refused.
181+
- The Drive API must be enabled in the same project the OAuth clients belong
182+
to. Sign-in can succeed while every sync then fails.

lib/controllers/google_drive_sync_controller.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,38 @@ class GoogleDriveSyncController with ChangeNotifier {
8585
notifyListeners();
8686
return result;
8787
} catch (error) {
88-
_error = 'Google sign-in failed: $error';
88+
_error = _signInMessage(error);
8989
notifyListeners();
9090
return false;
9191
}
9292
}
9393

94+
/// Turns a sign-in failure into something the reader can act on.
95+
///
96+
/// The plugin's own text describes what the credential layer saw, not what
97+
/// is wrong. "Account reauth failed" in particular is what Android reports
98+
/// when it cannot match the running app to an OAuth client, which is a
99+
/// setup problem in the Google Cloud project rather than anything the user
100+
/// did, and is easy to hit after the app's signing key changes.
101+
static String _signInMessage(Object error) {
102+
final text = error.toString();
103+
104+
if (text.contains('reauth failed') || text.contains('10:')) {
105+
return 'Google refused the sign-in because this build is not '
106+
'registered in its Google Cloud project. An Android OAuth client '
107+
'is needed for the package name and the signing certificate of this '
108+
'exact build. See the Google Drive sync guide in the docs.';
109+
}
110+
if (text.contains('canceled') || text.contains('cancelled')) {
111+
return 'Sign-in was cancelled.';
112+
}
113+
if (text.contains('network') || text.contains('SocketException')) {
114+
return 'Sign-in could not reach Google. Check the connection and try '
115+
'again.';
116+
}
117+
return 'Google sign-in failed: $error';
118+
}
119+
94120
Future<void> disconnect() async {
95121
_syncTimer?.cancel();
96122
await _auth.signOut();

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
1515
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1616
# In Windows, build-name is used as the major, minor, and patch parts
1717
# of the product and file versions while build-number is used as the build suffix.
18-
version: 2.2.0
18+
version: 2.2.1
1919
environment:
2020
sdk: ^3.12.0
2121
# Dependencies specify other packages that your package needs in order to work.

0 commit comments

Comments
 (0)