科尔多瓦和Proguard:takePicture上的相机插件NPE [英] Cordova and proguard : Camera Plugin NPE on takePicture

查看:85
本文介绍了科尔多瓦和Proguard:takePicture上的相机插件NPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,是否有人已经要求过这个. 我是Stack的新手,但没有找到解决方案.

sorry if someone already asked for this. I'm very new on Stack, and i didn't found a solution.

这是我缩小应用程序使用后得到的堆栈.

Here is the stack i get form the usage of my app after I minified it.

08-29 13:27:30.330 10037-10192/? E/PluginManager: Uncaught exception from plugin
                                              java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
                                                  at android.support.v4.content.FileProvider.parsePathStrategy(Unknown Source)
                                                  at android.support.v4.content.FileProvider.getPathStrategy(Unknown Source)
                                                  at android.support.v4.content.FileProvider.getUriForFile(Unknown Source)
                                                  at org.apache.cordova.camera.CameraLauncher.takePicture(Unknown Source)
                                                  at org.apache.cordova.camera.CameraLauncher.callTakePicture(Unknown Source)
                                                  at org.apache.cordova.camera.CameraLauncher.execute(Unknown Source)
                                                  at org.apache.cordova.CordovaPlugin.execute(Unknown Source)
                                                  at org.apache.cordova.PluginManager.exec(Unknown Source)
                                                  at org.apache.cordova.CordovaBridge.jsExec(Unknown Source)
                                                  at org.apache.cordova.engine.SystemExposedJsApi.exec(Unknown Source)
                                                  at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
                                                  at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:7)
                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                  at android.os.Looper.loop(Looper.java:154)
                                                  at android.os.HandlerThread.run(HandlerThread.java:61)

这是我的保护文件:

    # ionic
-keep class org.apache.cordova.** { *; }
-keep class org.apache.cordova.camera.** { *; }
-keep public class * extends org.apache.cordova.CordovaPlugin
-keep class com.ionic.keyboard.IonicKeyboard.** { *; }

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

# Not sure if needed, found it in several documentations
-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

#-libraryjars ./libs/android-support-v4.jar
-dontwarn android.support.v4.**

-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment
-keep class android.support.v4.content.FileProvider

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-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
-dontwarn android.net.SSLCertificateSocketFactory
-dontwarn android.net.http.*

-keepattributes *Annotation*

如果我使用从画廊中选择"选项,一切都很好,但是每次尝试使用相机时,都会出现此错误.

If i use the "choose from the gallery" item, all is ok, but every time i try to use the camera i get this error.

对于Android清单,我有这个:

For the android manifest i have this :

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="24" android:versionName="2.4" package="" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true"
            android:name="android.support.v4.content.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
        </provider>
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

</manifest>

请注意,我从清单中删除了软件包名称(仅针对此文章,该名称仅在堆栈中,在我的内部版本中就是该名称)

Notice that i removed the package name from the manifest (for this post on stack only, in my build there is the name)

如果我使用minifyenabled false删除了proguard,则该应用程序正常并且可以处理相机.

If i remove proguard with minifyenabled false, the app is ok and deals with the camera.

我不知道缩小了什么,我应该增加以保持? 或者,也许您有提示/技巧来发现我的方法中有什么不好?

I dont know what is shrinked and i should add to keep ? Or perhaps have you a hint / tips to found what is bad in my method?

谢谢.

推荐答案

如果仍然有人卡在此

将此行添加到您的保护规则

Add this line to Your proguard rules

-keep class com.abc.xyz.BuildConfig { *; }

其中com.abc.xyz是您的软件包名称

where com.abc.xyz is your Package name

就这样...

稍后谢谢...

快乐的编码

这篇关于科尔多瓦和Proguard:takePicture上的相机插件NPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆