googleCredential fails on Android
See original GitHub issueThanks for stopping by to let us know something could be better!
GoogleCredential tries to use the Android/Apache version of Base64, not the one in the dependency. As this version is old, it doesn’t have the method decodeBase64.
This fails on the emulators and on a real Android device.
The code in client.util.base64 explicitly refers to the apache commons version of Base64, but this is not found at run-time.
Environment details
- OS: Android 6 & 7
- Java version: 1.8.0
- google-api-java-client version: 27
Steps to reproduce
private static String getAccessToken(InputStream gc) throws IOException { GoogleCredential googleCredential = GoogleCredential .fromStream(gc) .createScoped(Arrays.asList(SCOPES));
Stacktrace
Caused by: java.lang.NoSuchMethodError: No static method decodeBase64(Ljava/lang/String;)[B in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of ‘org.apache.commons.codec.binary.Base64’ appears in /system/framework/org.apache.http.legacy.boot.jar) at com.google.api.client.util.Base64.decodeBase64(Base64.java:101) at com.google.api.client.util.PemReader.readNextSection(PemReader.java:106) at com.google.api.client.util.PemReader.readFirstSectionAndClose(PemReader.java:135) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.privateKeyFromPkcs8(GoogleCredential.java:904) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStreamServiceAccount(GoogleCredential.java:877) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStream(GoogleCredential.java:260) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStream(GoogleCredential.java:226) at me.steve.TumblerListen.gCredTask.getAccessToken(gCredTask.java:33)
#### External references such as API reference guides used
Libraries in Gradle dependency list include
implementation 'commons-codec:commons-codec:1.11'
implementation 'com.google.http-client:google-http-client:1.27.0'
implementation 'com.google.api-client:google-api-client:1.27.0'
- ?
#### Any additional information below
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6
Top GitHub Comments
Downgrading to 1.25.0 or earlier should work until 1.28.0 is released (soon).
The google-http-client was not correctly shading/jarjar’ing the apache common-codec version and it conflicts with the built-in android one.