nisrulz / qreader

:white_square_button: [Android Library] Read QR codes using google's mobile vision api, but without the hassle
http://nisrulz.github.io/qreader
Apache License 2.0
371 stars 108 forks source link

Error building with proguard #47

Closed datnt1987 closed 7 years ago

datnt1987 commented 7 years ago

I have build my project with proguard using QReader Libs but it throw error "can't find common super class ...LatLngBounds (google gms), but when I remove QReader Libs, my project build successfully. I've tried to add into proguard-rule.pro -dontwarn github.nisrulz.qreader. -keep class github.nisrulz.qreader. { *; }

But error still appear. Please guide me how to fix this. Thanks

nisrulz commented 7 years ago

@datnt1987 can you share the complete error log?

datnt1987 commented 7 years ago

hi @nisrulz here is my full error log: Warning:Exception while processing task java.io.IOException: java.lang.IllegalArgumentException: Can't find common super class of [com/google/android/gms/maps/model/LatLngBounds] (with 1 known super classes) and [java/util/Iterator] (with 2 known super classes)

It seem not relate to the Libs, but when I remove "compile libs", It run ok.

nisrulz commented 7 years ago

@datnt1987 try adding the below to your proguard file

-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

A more detailed version of proguard rules would be as mentioned in official docs

Use this if the above version doesnot work

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames class * implements android.os.Parcelable
-keepclassmembers class * implements android.os.Parcelable {
  public static final *** CREATOR;
}

-keep @interface android.support.annotation.Keep
-keep @android.support.annotation.Keep class *
-keepclasseswithmembers class * {
  @android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
  @android.support.annotation.Keep <methods>;
}

-keep @interface com.google.android.gms.common.annotation.KeepName
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
  @com.google.android.gms.common.annotation.KeepName *;
}

-keep @interface com.google.android.gms.common.util.DynamiteApi
-keep public @com.google.android.gms.common.util.DynamiteApi class * {
  public <fields>;
  public <methods>;
}

-dontwarn android.security.NetworkSecurityPolicy
datnt1987 commented 7 years ago

Dear @nisrulz , I've tried both but nothing has changed. It still occur error.

-keep public class com.google.android.gms. { public ; } -dontwarn com.google.android.gms.**

I've already insert these before.

nisrulz commented 7 years ago

@datnt1987 Let me run this through some tests and then I will get back to you.

datnt1987 commented 7 years ago

Thanks in advance, expect answering from you, @nisrulz

nisrulz commented 7 years ago

@datnt1987 I updated the dependencies today and pushed the code to develop branch. When I ran the code with proguard enabled, without any change, the app ran properly.

Could you run the example app on your side with proguard enable from the develop branch. If that works I will release the updated library to jcenter and you can then sync it up for it start working with your app.

As I see it is some issue with last google play dependency which QREader depends on.

Let me know if it works.

datnt1987 commented 7 years ago

Dear @nisrulz , I've tried both branch (master and dev), the app ran properly and I cannot confirm that you changed at dev branch works.

By the way, a thing that I forget to tell you that I'm using ver 2.0.1 (not 2.1.1)

nisrulz commented 7 years ago

Ok, can you try using the latest version i have pushed (v 2.1.2)

use this in your build.gradle

compile 'com.github.nisrulz:qreader:2.1.2'
datnt1987 commented 7 years ago

Warning:Exception while processing task java.io.IOException: java.lang.IllegalArgumentException: > Can't find common super class of [com/google/android/gms/maps/model/LatLngBounds] (with 1 known super classes) and [java/util/Iterator] (with 2 known super classes)

I'm sorry but It's still not work for me with the newest version. :(.

I think that libs using some google service modules and when proguard, qreader libs not keep those classes. In this case, I found that I cannot access the super class of LatLngBounds is AbstractSafeParcelable (I can access this when not using QREader libs)

This is just my guess.

datnt1987 commented 7 years ago

In my project, I also use react native lib that have com/airbnb/android/react/maps/AirMapView. When building project by using command line:

Unexpected error while performing partial evaluation: Class = [com/airbnb/android/react/maps/AirMapView] Method = [fitToElements(Z)V] Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [com/google/android/gms/maps/model/LatLngBounds] (with 1 known super classes) and [java/util/Iterator] (with 2 known super classes))

Method detail

public void fitToElements(boolean animated) {
        LatLngBounds.Builder builder = new LatLngBounds.Builder();

        boolean addedPosition = false;

        for (AirMapFeature feature : features) {
            if (feature instanceof AirMapMarker) {
                Marker marker = (Marker) feature.getFeature();
                builder.include(marker.getPosition());
                addedPosition = true;
            }
            // TODO(lmr): may want to include shapes / etc.
        }
        if (addedPosition) {
            LatLngBounds bounds = builder.build();
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, baseMapPadding);
            if (map == null) {
                return;
            }
            if (animated) {
                startMonitoringRegion();
                map.animateCamera(cu);
            } else {
                map.moveCamera(cu);
            }
        }
    }

So is that have conflicts here ???

nisrulz commented 7 years ago

Ok this is interesting. Because QREader doesnot use any google maps dependency. Check here

This looks more like a conflict, thought I donot have a solution for this.

I do not have any idea about the react native part of this problem. Probably someone who has worked with react native could chime in. Try posting this on stackoverflow even.

datnt1987 commented 7 years ago

Yes @nisrulz, I think I should find solution in another way. Thank so much for supporting me like this, I respect that.