这是我在缩小它后使用我的应用程序获得的堆栈。
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*
如果我使用&#34;从图库中选择&#34;项目,一切正常,但每次我尝试使用相机时都会收到此错误。
对于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,该应用程序可以正常处理相机。
我不知道什么是收缩,我应该加上保持? 或者或许你有一个提示/提示,找到我方法中的坏处?
THX。
答案 0 :(得分:3)
如果有人仍然坚持这个
将此行添加到您的proguard规则
-keep class com.abc.xyz.BuildConfig { *; }
其中com.abc.xyz是您的包名称
就是这样......
稍后再谢谢你......
快乐编码
答案 1 :(得分:1)
嗨我解决了同样的问题。有没有classnotfounderror?在我的问题中,NPE有一个classnotfoundexception底部。在我在proguard-rules中添加了那个不合适的类之后,问题就解决了。
我的问题日志就像 java.lang.ClassNotFoundException:com.xyz.XYZ.BuildConfig
Uncaught exception from plugin java.lang.NullPointerException:
Attempt to invoke virtual method 'android.content.res.XmlResourceParser
android.content.pm.ProviderInfo.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:145)
at android.os.HandlerThread.run(HandlerThread.java:61)
09-03 11:38:37.630 6926-6926/com.xyz.XYZ D/SystemWebChromeClient: file:///android_asset/www/js/bundles/fileUploadMobile_bundle.js: Line 1 : Failed because: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
09-03 11:38:37.630 6926-6926/com.xyz.XYZ I/chromium: [INFO:CONSOLE(1)] "Failed because: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference", source: file:///android_asset/www/js/bundles/fileUploadMobile_bundle.js (1)
09-03 11:38:37.690 6926-9554/com.xyz.XYZ D/BuildHelper: Unable to get the BuildConfig, is this built with ANT?
09-03 11:38:37.690 6926-9554/com.xyz.XYZ W/System.err: **java.lang.ClassNotFoundException: com.xyz.XYZ.BuildConfig**
之后在proguard-rules
中添加该行-keep public class com.xyz.XYZ.BuildConfig
-keepclassmembers class com.xyz.XYZ.BuildConfig {
public *;
}
答案 2 :(得分:1)
我也遇到了同样的问题,以下问题解决了我:
更新config.xml文件。
<preference name="applicationId" value="{PACKAGE_ID}"/>
其中{PACKAGE_ID}被项目的Android Package ID替换。答案 3 :(得分:0)
在Manifest文件中,在应用程序标记内添加它。我试过这个工作
以下是我的Manifest xml文件中的提供程序部分:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>