Android App crashes after proguard obfuscation (Google plus people search)

徘徊边缘 提交于 2020-01-25 11:50:36

问题


I added some code to my app to search people on Google Plus. This code works well without Proguard. After running proguard to obfuscate the code, my app crashes when searching for people on google plus.

09-14 10:21:51.346: E/AndroidRuntime(12527): FATAL EXCEPTION: AsyncTask #4
09-14 10:21:51.346: E/AndroidRuntime(12527): Process: com.mapegames.sudokukings, PID: 12527
 java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:300)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:864)
 Caused by: java.lang.NullPointerException
    at com.google.api.client.util.Types.getActualParameterAtPosition(SourceFile:327)
    at com.google.api.client.util.Types.getIterableParameter(SourceFile:307)
    at com.google.api.client.http.HttpHeaders.parseHeader(SourceFile:1158)
    at com.google.api.client.http.HttpHeaders.fromHttpResponse(SourceFile:989)
    at com.google.api.client.http.HttpResponse.<init>(SourceFile:148)
    at com.google.api.client.http.HttpRequest.execute(SourceFile:969)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(SourceFile:410)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(SourceFile:343)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(SourceFile:460)
    at com.mapegames.sudokukings.PlayersActivity$getPeople.doInBackground(SourceFile:904)
    at com.mapegames.sudokukings.PlayersActivity$getPeople.doInBackground(SourceFile:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)

... 4 more

I have tried to keep the classes in the proguard config-file which are related to the google.api.sevices.plus, but this doesn't work.

-keep class com.mapegames.sudokukings.** { *; }
-keep class com.google.api.client.** { *; }
-keep class com.google.api.services.plus.** { *; }
-keep class com.google.api.services.plus.model.** { *; }
-keep class java.lang.** { *; }
-keep class android.os.** { *; }

It seems that the error occurs at the following execute "src[0].execute()" in the code below.

import com.google.api.services.plus.Plus;
import com.google.api.services.plus.model.PeopleFeed;

private Plus.People.Search searchPeople;

private void searchPeople(String name) throws IOException {
    searchPeople = plusSvc.people().search(name);
    searchPeople.setMaxResults(5L);
    status.setText(getString(R.string.searching) + " 10%");
    Log.i(TAG, "searchPeople: " + searchPeople);

    new getPeople().execute(searchPeople);
}

private class getPeople extends AsyncTask<Plus.People.Search, Void, PeopleFeed> {

     public PeopleFeed doInBackground(Plus.People.Search... src) {
         Log.i(TAG, "Start PeopleSearch");
         try {
             Log.i(TAG, "Try PeopleSearch: " + src[0]);
             return src[0].execute();
         } catch (IOException e) {
             Log.i(TAG, "Catch PeopleSearch");
             e.printStackTrace();
             return null;
         }
     }

     protected void onPostExecute(PeopleFeed feed) {
         Log.i(TAG, "Set PeopleSearch");
         setPeople(feed);
     }
 }

The last lines of my Log-file below show the error occurs at "src[0].execute()".

09-13 13:17:14.170: I/PL(2881): searchPeople: {b=yhb, f=5, key=AIzaSyAfaXmYlCopeZuV-Rk5rdwGOBP3Pdkp24o}
09-13 13:17:14.170: I/PL(2881): Start PeopleSearch
09-13 13:17:14.170: I/PL(2881): Try PeopleSearch: {b=yhb, f=5, key=AIzaSyAfaXmYlCopeZuV-Rk5rdwGOBP3Pdkp24o}

Im not sure this information above is sufficient enough, so please let me know when additional information is required.


回答1:


Can you try:

-keep class com.google.api.services.plus.** { *; }

You can also check what gets taken away by looking at the proguard output files.
EDIT - Your problem might be similar to these:

  • http://softwyer.wordpress.com/2012/10/20/android-google-drive-sdk-and-proguard/
  • Google Drive API doesn't play well with ProGuard (NPE)

These are for Drive, but the location of the NPE is similar, and they provide a working proguard config you can start with.



来源:https://stackoverflow.com/questions/25823449/android-app-crashes-after-proguard-obfuscation-google-plus-people-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!