what3words / w3w-android-wrapper

MIT License
1 stars 2 forks source link

convertToCoordinates: isSuccessful returns true but getCoordinates returns null #12

Closed DennyWeinberg closed 3 years ago

DennyWeinberg commented 3 years ago

That happens only in release variant. In debug it works. Gradle:

    buildTypes {
        // If we use the same keystore for debug and release, we don't have to wipe all preferences
        debug {
            signingConfig signingConfigs.releaseConfig
            zipAlignEnabled true
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.releaseConfig
            zipAlignEnabled true
        }
    }

[...]

    // what3words
    implementation 'com.what3words:w3w-android-wrapper:3.1.10'

What am I doing wrong?

Call:

                    // what3words
                    What3WordsV3 what3words = new What3WordsV3(activity.getString(R.string.what3WordsAPIKey), activity);
                    ConvertToCoordinates result = what3words.convertToCoordinates(query).execute();
                    Log.d("xxx", result.toString());
                    Log.d("xxx", String.format("%s", result.isSuccessful()));
                    Log.d("xxx", result.getCoordinates().toString());

It logs the following when I built in release variant: xxx true xxx {} NullPointerException

In debug it works (I get my coordinates)

Proguard:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\denny_000\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-dontwarn org.apache.commons.imaging.**
-dontwarn com.google.android.gms.internal.**
-dontwarn uk.co.senab.photoview.**
-dontwarn org.apache.velocity.**
-dontwarn com.google.auto.**
-dontwarn autovalue.shaded.com.google.common.auto.common.**
-dontwarn autovalue.shaded.com.google.common.common.**
-dontwarn autovalue.shaded.org.apache.commons.lang.builder.**

# EventBus
-keepclassmembers class ** {
    public void onEvent*(**);
}
-keep class de.greenrobot.** {*;}
-keep public enum org.greenrobot.eventbus.ThreadMode { public static *; }

-keep class android.support.v7.widget.SearchView { *; }

-keepattributes EnclosingMethod
-keepattributes InnerClasses

# gcm. Source: http://stackoverflow.com/questions/18646899/proguard-cant-find-referenced-class-com-google-android-gms-r
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

# Guava
-keep class com.google.j2objc.annotations.** { *; }
-dontwarn   com.google.j2objc.annotations.**
-keep class java.lang.ClassValue { *; }
-dontwarn   java.lang.ClassValue
-keep class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement { *; }
-dontwarn   org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Guava 20.0. Source: http://stackoverflow.com/questions/9120338/proguard-configuration-for-guava-with-obfuscation-and-optimization/20935044
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.concurrent.LazyInit
-dontwarn com.google.errorprone.annotations.ForOverride

# AppIntro
-dontwarn com.github.paolorotolo.**
-keep class com.github.paolorotolo.** {*;}

# RenderScript
-keepclasseswithmembernames class * {
native <methods>;
}
-keep class androidx.renderscript.** { *; }

# Google Drive
-keep class * extends com.google.api.client.json.GenericJson {
*;
}
-keep class com.google.api.services.drive.** {
*;
}

# Glide
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep class com.bumptech.glide.GeneratedAppGlideModuleImpl

# Dropbox
-keep class com.dropbox.** {*;}
-dontwarn com.dropbox.**

# Do not change class names of Serializable because of cache
-keep class * implements java.io.Serializable

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    !private <fields>;
    !private <methods>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Kryo
-keep class com.esotericsoftware.kryo.** {*;}
-dontwarn sun.reflect.**
-dontwarn java.beans.**
-keep,allowshrinking class com.esotericsoftware.** {
   <fields>;
   <methods>;
}
-keep,allowshrinking class java.beans.** { *; }
-keep,allowshrinking class sun.reflect.** { *; }
-keep,allowshrinking class com.esotericsoftware.kryo.** { *; }
-keep,allowshrinking class com.esotericsoftware.kryo.io.** { *; }
-keep,allowshrinking class sun.nio.ch.** { *; }
-dontwarn sun.nio.ch.**
-dontwarn sun.misc.**

# Shape Image View
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.* { *; }
-keepattributes *Annotation,Signature
-dontwarn com.github.siyamed.**
-keep class com.github.siyamed.shapeimageview.**{ *; }
-keep class org.xmlpull.v1.** { *; }

# will keep line numbers and file name obfuscation
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# Fix OAuth Drive API failure for release builds
-keep class * extends com.google.api.client.json.GenericJson { *; }
-keep class com.google.api.services.drive.** { *; }
-keepclassmembers class * { @com.google.api.client.util.Key <fields>; }

# Gson
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

# Prevent Caused by: java.lang.NoSuchMethodError: No virtual method setEntity(Lorg/apache/http/f;)V in class Lorg/apache/http/client/methods/HttpPost; or its super classes (declaration of 'org.apache.http.client.methods.HttpPost' appears in /system/framework/org.apache.http.legacy.jar)
-keep class org.apache.** { *; }
DennyWeinberg commented 3 years ago

It works when I comment minifyEnabled true. But I don't want to publish an app without it!

DennyWeinberg commented 3 years ago

Oh wow, I got it working with the following new line in my pro guard file: -keep class com.what3words.** { *; }

andycurriew3w commented 3 years ago

Hi @DennyWeinberg

Thank you for flagging this. We'll add to the readme but are going to review the proguard setup first. Are you ok to close this issue?