添加proguard后用于cordova的相机插件中的java NullPointerException
Posted
技术标签:
【中文标题】添加proguard后用于cordova的相机插件中的java NullPointerException【英文标题】:java NullPointerException in camera plugin for cordova after adding proguard 【发布时间】:2018-06-05 16:04:36 【问题描述】:我正在尝试将 Proguard 添加到我的 ionic cordova 项目中。除了相机cordova 插件的take_picture
方法外,一切都运行良好。 proguard 规则主要是通过试错法添加的,所以可能会出现我看不到的错误,所以如果有处理 proguard 经验的人可以提供帮助,那就太好了。
这是我的proguard规则-
-keep class com.android.vending.licensing.ILicensingService
-keepattributes *Annotation*
-keepclassmembers enum *
public static **[] values();
public static ** valueOf(java.lang.String);
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
# Enable proguard with Cordova
-keep class org.apache.** *;
-keep public class * extends org.apache.cordova.CordovaPlugin
-keep class com.google.android.gms.dynamite.DynamiteModule$DynamiteLoaderClassLoader java.lang.ClassLoader sClassLoader;
-keep class com.google.android.gms.dynamite.descriptors.com.google.android.gms.flags.ModuleDescriptor int MODULE_VERSION;
-keep class com.google.android.gms.dynamite.descriptors.com.google.android.gms.flags.ModuleDescriptor java.lang.String MODULE_ID;
-keep class org.apache.cordova.CordovaBridge org.apache.cordova.PluginManager pluginManager;
-keep class org.apache.cordova.CordovaInterfaceImpl org.apache.cordova.PluginManager pluginManager;
-keep class org.apache.cordova.CordovaResourceApi org.apache.cordova.PluginManager pluginManager;
-keep class org.apache.cordova.CordovaWebViewImpl org.apache.cordova.PluginManager pluginManager;
-keep class org.apache.cordova.ResumeCallback org.apache.cordova.PluginManager pluginManager;
-keep class org.apache.cordova.engine.SystemWebViewEngine org.apache.cordova.PluginManager pluginManager;
-keep class com.google.gson.internal.UnsafeAllocator ** theUnsafe;
-keep class me.leolin.shortcutbadger.ShortcutBadger ** extraNotification;
-keep class me.leolin.shortcutbadger.impl.XiaomiHomeBadger ** messageCount;
-keep class me.leolin.shortcutbadger.impl.XiaomiHomeBadger ** extraNotification;
-dontnote org.apache.harmony.xnet.provider.jsse.NativeCrypto
-dontnote sun.misc.Unsafe
-keep class com.worklight.androidgap.push.** *;
-keep class com.worklight.wlclient.push.** *;
# Enable proguard with Google libs
-keep class com.google.** *;
-dontwarn com.google.common.**
-dontwarn com.google.ads.**
-keep class net.sqlcipher.** *;
-dontwarn net.sqlcipher.**
-keep class org.codehaus.** *;
-keepattributes *Annotation*,EnclosingMethod
-keepclassmembers enum *
public static **[] values();
public static ** valueOf(java.lang.String);
# Remove debug logs in release build
-assumenosideeffects class android.util.Log
public static *** d(...);
# These classes contain references to external jars which are not included in the default MobileFirst project.
-dontwarn com.worklight.common.internal.WLTrusteerInternal*
-dontwarn com.worklight.jsonstore.**
-dontwarn org.codehaus.jackson.map.ext.*
-dontwarn com.worklight.androidgap.push.GCMIntentService
-dontwarn com.worklight.androidgap.plugin.WLInitializationPlugin
-keep class android.**
-dontwarn android.net.SSLCertificateSocketFactory
-dontwarn android.net.http.*
-keepclasseswithmembernames class android.support.v4.content
-dontwarn org.apache.**
#-keep class org.** *;
任何帮助都会很棒,等待肯定的答复。
【问题讨论】:
【参考方案1】:如果有人仍然卡在这个问题上
将此行添加到您的 proguard 规则中
-keep class com.abc.xyz.BuildConfig *;
com.abc.xyz 是你的包名
就是这样......
稍后谢谢我...
快乐编码
【讨论】:
以上是关于添加proguard后用于cordova的相机插件中的java NullPointerException的主要内容,如果未能解决你的问题,请参考以下文章
Cordova 相机插件适用于模拟器,而不适用于 Android 设备
拍摄照片后,Ionic cordova 相机插件间歇性崩溃(使用 Firebase 图像上传)