Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializing MyApi using builder giver Exception #1450

Closed
sumitiu opened this issue Dec 10, 2019 · 8 comments · Fixed by #1467
Closed

Initializing MyApi using builder giver Exception #1450

sumitiu opened this issue Dec 10, 2019 · 8 comments · Fixed by #1467
Assignees
Labels
android type: question Request for information or clarification. Not an issue.

Comments

@sumitiu
Copy link

sumitiu commented Dec 10, 2019

Caused by: java.lang.IllegalStateException: No successful match so far
at java.util.regex.Matcher.ensureMatch(Matcher.java:1116)
at java.util.regex.Matcher.group(Matcher.java:382)
at com.google.api.client.googleapis.GoogleUtils.(GoogleUtils.java:66)
at com.idragonit.backend.myApi.MyApi.(MyApi.java:46) 
Version Using: implementation 'com.google.api-client:google-api-client:1.30.6'
in my andoid backed library
In GoogleUtils.java line number 64
Matcher versionMatcher = VERSION_PATTERN.matcher(VERSION);
I am getting VERSION string 0.0

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Dec 10, 2019
@codyoss codyoss added type: question Request for information or clarification. Not an issue. android and removed triage me I really want to be triaged. labels Dec 12, 2019
@Samikay
Copy link

Samikay commented Dec 13, 2019

Hey there, if you'd like this to work in the interim I've answered an SO post about the problem here: https://stackoverflow.com/questions/59243821/youtube-api-exception-in-initializer-error/59298544#59298544

And unfortunately, I duplicated this issue here if someone would like to decide which issue to close: #1451

Cheers

@elharo
Copy link
Contributor

elharo commented Jan 2, 2020

This should be fixed in 1.30.7.

@elharo elharo closed this as completed Jan 2, 2020
@adityabhaskar
Copy link

Still getting this error on 1.30.7 with minifyEnabled. Doesn't occur when minifyEnabled is set to false.

E: FATAL EXCEPTION: main
        Process: ..., PID: 9737
        java.lang.ExceptionInInitializerError
            at com.google.api.services.drive.Drive.<clinit>(SourceFile:48)
            at com.google.api.services.drive.Drive$Builder.build(SourceFile:9805)
            at g.a.a.k.d.a$a.a(SourceFile:55)

Code where it occurs..

                Drive.Builder(
                    NetHttpTransport(),
                    JacksonFactory(),
                    credential
                                )
                    .setApplicationName("...")
Line 55 ->>                    .build()

@elharo
Copy link
Contributor

elharo commented Jan 8, 2020

To be clear, it didn't whether minifyEnabled was true or false, right?

I'm not an Android expert so I need to dig into what minifyEnabled implies, but I'm guessing that it's somehow stripping code and removing code that is in fact accessed by reflection.

@elharo elharo reopened this Jan 8, 2020
@elharo
Copy link
Contributor

elharo commented Jan 8, 2020

Bingo:

For most situations, the default ProGuard rules file (proguard-android- optimize.txt) is sufficient for R8 to remove only the unused code. However, some situations are difficult for R8 to analyze correctly and it might remove code your app actually needs. Some examples of when it might incorrectly remove code include:

When your app calls a method from the Java Native Interface (JNI)
When your app looks up code at runtime (such as with reflection)

Testing your app should reveal any errors caused by inappropriately removed code, but you can also inspect what code was removed by generating a report of removed code.

To fix errors and force R8 to keep certain code, add a -keep line in the ProGuard rules file. For example:

-keep public class MyClass

Alternatively, you can add the @keep annotation to the code you want to keep. Adding @keep on a class keeps the entire class as-is. Adding it on a method or field will keep the method/field (and its name) as well as the class name intact. Note that this annotation is available only when using the AndroidX Annotations Library and when you include the ProGuard rules file that is packaged with the Android Gradle plugin, as described in the section about how to enable shrinking.

There are many considerations you should make when using the -keep option; for more information about customizing your rules file, read the ProGuard Manual. The Troubleshooting section outlines other common problems you might encounter when your code gets stripped away.

@elharo
Copy link
Contributor

elharo commented Jan 8, 2020

The problem is from https://github.com/googleapis/google-api-java-client/pull/1452/files and I think this line in GoogleUtils:

InputStream inputStream =
      try (InputStream inputStream =
        GoogleUtils.class.getResourceAsStream("google-api-client.properties")) 

@elharo
Copy link
Contributor

elharo commented Jan 8, 2020

We should probably apply the annotation androidx.annotation.Keep to GoogleUtils.

@elharo
Copy link
Contributor

elharo commented Jan 8, 2020

Meanwhile try adding

-keep public class com.google.api.client.googleapis.GoogleUtils

or some such thing to your proguard rules file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants