dji-sdk / Mobile-SDK-Android

DJI Mobile SDK for Android: http://developer.dji.com/mobile-sdk/
Other
978 stars 579 forks source link

When open proguard, app will show 'The key does not match the format: component/index/key with index being a number or *.' error when invoke takeoffaction method #500

Open ohaujingjing opened 4 years ago

ohaujingjing commented 4 years ago

Everything goes find when debug with proguard closed, but when I open proguard for release, the error shows. The key does not match the format: component/index/key with index being a number or *. I copyed the same file of proguard-rules.pro from the dji sample code:

-keepattributes Exceptions,InnerClasses,*Annotation*,Signature,EnclosingMethod

-dontoptimize
-dontpreverify
-dontwarn okio.**
-dontwarn org.bouncycastle.**
-dontwarn dji.**
-dontwarn com.dji.**
-dontwarn sun.**
-dontwarn java.**
-dontwarn com.mapbox.**
-dontwarn okhttp3.internal.**
-dontwarn retrofit2.**

-dontwarn com.amap.api.**
-dontwarn com.a.a.**
-dontwarn com.autonavi.**
-keep class com.amap.api.**  {*;}
-keep class com.autonavi.**  {*;}
-keep class com.a.a.**  {*;}

-keepclassmembers enum * {
    public static <methods>;
}

-keepnames 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 void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keep public class * implements androidx.versionedparcelable.VersionedParcelable

-keep,allowshrinking class * extends dji.publics.DJIUI.** {
    public <methods>;
}

-keep class net.sqlcipher.** { *; }

-keep class net.sqlcipher.database.* { *; }

-keep class dji.** { *; }

-keep class com.dji.** { *; }

-keep class com.google.** { *; }

-keep class org.bouncycastle.** { *; }

-keep,allowshrinking class org.** { *; }

-keep class com.squareup.wire.** { *; }

-keep class sun.misc.Unsafe { *; }

-keep class com.secneo.** { *; }

-keep class org.greenrobot.eventbus.**{*;}

-keepclasseswithmembers,allowshrinking class * {
    native <methods>;
}

-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

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

-keepclassmembers class * extends android.app.Service
-keepclassmembers public class * extends android.view.View {
    void set*(***);
    *** get*();
}
-keepclassmembers class * extends android.app.Activity {
    public void *(android.view.View);
}
-keep class android.support.** { *; }
-keep class androidx.** { *; }
-keep class android.media.** { *; }
-keep class okio.** { *; }
-keep class com.lmax.disruptor.** {
    *;
}

-dontwarn com.mapbox.services.android.location.LostLocationEngine
-dontwarn com.mapbox.services.android.location.MockLocationEngine
-keepclassmembers class * implements android.arch.lifecycle.LifecycleObserver {
    <init>(...);
}
# ViewModel's empty constructor is considered to be unused by proguard
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
    <init>(...);
}
# keep Lifecycle State and Event enums values
-keepclassmembers class android.arch.lifecycle.Lifecycle$State { *; }
-keepclassmembers class android.arch.lifecycle.Lifecycle$Event { *; }
# keep methods annotated with @OnLifecycleEvent even if they seem to be unused
# (Mostly for LiveData.LifecycleBoundObserver.onStateChange(), but who knows)
-keepclassmembers class * {
    @android.arch.lifecycle.OnLifecycleEvent *;
}

-keepclassmembers class * implements android.arch.lifecycle.LifecycleObserver {
    <init>(...);
}

-keep class * implements android.arch.lifecycle.LifecycleObserver {
    <init>(...);
}
-keepclassmembers class android.arch.** { *; }
-keep class android.arch.** { *; }
-dontwarn android.arch.**

-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String,int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}
dji-dev commented 4 years ago

Agent comment from Luce Luo in Zendesk ticket #33153:

Dear Customer,

Thank you for contacting DJI. To help us collect questions in detail, please fill in the form below and we will handle this ticket once we have received it. https://formcrafts.com/a/dji-developer-feedback-en

Thanks,

Luce Luo DJI Dev Team

addriumruss commented 3 years ago

@ohaujingjing 最近我这边上传航线也出现了这个问题,后来发现是更新到最新4.14-trial版本后,build.gradle少了一句"doNotStrip "//libDJISDKLOGJNI.so"", 这句是最新版新增的,github网页上没有明显给出提示! 添加这句之后重新编译release版就成功上传航线。 仅供参考~

fernando-s97 commented 2 years ago

Same issue here, and my build.gradle has the doNotStrip "*/*/libDJISDKLOGJNI.so"

DJI-William commented 2 years ago

Do you guys have the same content as https://github.com/dji-sdk/Mobile-SDK-Android/blob/master/Sample%20Code/app/proguard-rules.pro. If yes, please tell me how to reproduce the issue. This error commonly happen when you miss some settings in proguard-reles.pro.

fernando-s97 commented 2 years ago

@DJI-William Yes, my proguard-rules.pro has the same content of the file you provided.

In my case, I use the SDK inside a lib project, so my build.gradle of this lib project has this code:

defaultConfig {
    consumerProguardFiles 'proguard-rules.pro'
}

The app that uses this lib project has the following build.gradle code:

defaultConfig {
    proguardFiles getDefaultProguardFile('proguard-android.txt')
}

buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
    }
}

For me, the issue happens when I run a waypoint mission, so:

  1. Create a mission
  2. Load it
  3. Upload it
  4. Start it

The step 4 will fail with The key does not match the format: component/index/key with index being a number or *.

OBS: If I disable the shrinkResources and minifyEnabled, the issue no longer happens. OBS 2: I'm executing the app in release mode

DJI-William commented 2 years ago

@fernando-s97 This issue means the program cannot find the correct class to load which is caused by minifyEnabled and shrinkResources rules. This is why you will find it works when disable minifyEnabled and shrinkResources . The proguard-reles.pro defines what class files should be keep after minified. We need to look at the rules.

fernando-s97 commented 2 years ago

@DJI-William Yeah, I'm aware of that. I added that observation just to "prove" this problem only happens when minifyEnabled and shrinkResources is enabled, which therefore might indicate the problem is with the proguard rules, but as stated above, the proguard-rules.pro is the same one you specified.

And just to avoid doubts, you're taking a look at this issue, or are waiting for some more info?

DJI-William commented 2 years ago

@fernando-s97 We have to reproduce on our site to solve this problem. However, running a waypointMission on our side does not trigger this error. We may need a reproduceable method on Android Sample.