其他分享
首页 > 其他分享> > android – Cordova和proguard:相机插件NPE on takePicture

android – Cordova和proguard:相机插件NPE on takePicture

作者:互联网

对不起,如果有人已经要求这个.
我是Stack的新手,我没有找到解决方案.

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

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)

这是我的proguard文件:

    # 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*

如果我使用“从图库中选择”项目,一切都还可以,但每次我尝试使用相机时都会出现此错误.

对于Android清单我有这个:

<?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>

请注意,我从清单中删除了包名称(仅限堆栈上的此帖子,在我的构建中有名称)

如果我删除了minifyenabled false的proguard,该应用程序是正常的,并处理相机.

我不知道什么是收缩,我应该添加保持?
或者或许你有一个提示/提示,找到我方法中的坏处?

谢谢.

解决方法:

如果有人仍然坚持这一点

将此行添加到您的proguard规则中

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

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

而已 ……

晚点再谢我…

快乐的编码

标签:android,cordova,plugins,android-proguard
来源: https://codeday.me/bug/20190828/1750652.html