地图标注 坐标转换 找不到so INVALID_USER_KEY INVALID_USER_SCODE
flutter在制作release包时会默认开启混淆/压缩,如果不显示关闭或者配置混淆规则,plugin中的类和资源会混淆或者被优化调,导致无法加载plugin需要的相关类和资源。
解决方案:
方案一:关闭混淆
在android/app/build.gradle的builgTypes的release里里增加如下配置:
minifyEnabled false//删除无用代码
shrinkResources false//删除无用资源
示例:
buildTypes {
release {
signingConfigsigningConfigs.releaseminifyEnabledfalse //删除无用代码
shrinkResourcesfalse //删除无用资源
}
}
在android/app目录下增加proguard-rules.pro用于配置混淆规则(如果已经存在混淆文件了,可以不必再创建),内容如下:
#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
#高德地图SDK配置
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.**{*;}
-keep class com.amap.api.trace.**{*;}
#高德等位SDK配置
-keep class com.amap.api.location.**{*;}
-keep class com.amap.api.fence.**{*;}
-keep class com.loc.**{*;}
-keep class com.autonavi.aps.amapapi.model.**{*;}
然后在android/app/build.gradle文件的builgTypes的release里指定混淆文件。示例:
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
相关参考文档:
flutter发布Android版APP:https://flutterchina.club/android-release/
flutter开启压缩混淆:https://flutterchina.club/android-release/#%E5%BC%80%E5%90%AF%E6%B7%B7%E6%B7%86%E5%8E%8B%E7%BC%A9