4

我们为 Ionic 安装了 Camera Plugin 并且遇到了这个错误:

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

我们已经尝试了 链接中提供的所有解决方案 我们如何修复它?我们的(原始)清单是:

 <?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.ionic.starter" 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: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="org.apache.cordova.camera.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
</provider>
<service android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService" />
<service android:name="org.apache.cordova.firebase.FirebasePluginMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="org.apache.cordova.firebase.FirebasePluginInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<receiver android:name="org.apache.cordova.firebase.OnNotificationOpenReceiver" />
</application>
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

11 月 20 日: 为了进一步解释,我们在代码中附加了 Camera 调用。第一个函数成功打开具有指定 sourceType 的库。第二个函数因上述错误源类型 CAMERA 而失败。我们在同一个项目中使用插件 QR Scanner,相机打开并且可以正常工作。

openGallery () {
let cameraOptions = {
  sourceType: this.Camera.PictureSourceType.PHOTOLIBRARY,
  destinationType: this.Camera.DestinationType.DATA_URL,      
  quality: 100,
  targetWidth: 1000,
  targetHeight: 1000,
  encodingType: this.Camera.EncodingType.JPEG,      
  correctOrientation: true
}
this.Camera.getPicture(cameraOptions)
.then(imageData => {
  this.base64Image = 'data:image/jpeg;base64,' + imageData;
err => console.log(err);});   


}

takePhoto() {
let cameraOptions = {
  sourceType: this.Camera.PictureSourceType.CAMERA,
  destinationType: this.Camera.DestinationType.FILE_URI,      
  quality: 100,
  targetWidth: 1000,
  targetHeight: 1000,
  encodingType: this.Camera.EncodingType.JPEG,      
  correctOrientation: true,
}
this.Camera.getPicture(cameraOptions)
.then(file_uri => {
  console.log(file_uri);
}, 
err => console.log(err));   


}
4

1 回答 1

3

将此行添加到您的 proguard 规则

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

com.abc.xyz 是你的包名

于 2019-07-29T14:40:44.553 回答