Ionic Android No resource found that matches the g

2019-05-08 06:08发布

问题:

Having an issue with Ionic when trying to build a project. At :processDebugResources I'm getting an error as below:

Failed to generate resource table for split ''
/Applications/MAMP/htdocs/APP/consumer/platforms/android/build/intermediates/res/debug/values-v23/values.xml:6: error: Error: No resource found that matches the given name (at 'cardBackgroundColor' with value '?android:attr/colorBackgroundFloating').

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Users/johnhoulder/Library/Android/sdk/build-tools/23.0.3/aapt package -f --no-crunch -I /Users/johnhoulder/Library/Android/sdk/platforms/android-22/android.jar -M /Applications/MAMP/htdocs/APP/consumer/platforms/android/build/intermediates/manifests/full/debug/AndroidManifest.xml -S /Applications/MAMP/htdocs/APP/consumer/platforms/android/build/intermediates/res/debug -A /Applications/MAMP/htdocs/APP/consumer/platforms/android/build/intermediates/assets/debug -m -J /Applications/MAMP/htdocs/APP/consumer/platforms/android/build/generated/source/r/debug -F /Applications/MAMP/htdocs/APP/consumer/platforms/android/build/intermediates/res/resources-debug.ap_ --debug-mode --custom-package com.munch_delivery.app -0 apk --output-text-symbols /Applications/MAMP/htdocs/APP/consumer/platforms/android/build/intermediates/symbols/debug
  Error Code:
    1
  Output:
    Failed to generate resource table for split ''
    /Applications/MAMP/htdocs/APP/consumer/platforms/android/build/intermediates/res/debug/values-v23/values.xml:6: error: Error: No resource found that matches the given name (at 'cardBackgroundColor' with value '?android:attr/colorBackgroundFloating').



* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.959 secs

/Applications/MAMP/htdocs/APP/consumer/platforms/android/cordova/node_modules/q/q.js:126
                    throw e;
                    ^
Error code 1 for command: /Applications/MAMP/htdocs/APP/consumer/platforms/android/gradlew with args: cdvBuildDebug,-b,/Applications/MAMP/htdocs/APP/consumer/platforms/android/build.gradle,-PcdvBuildArch=arm,-Dorg.gradle.daemon=true

Plugins:

  • cordova-plugin-facebook4
  • cordova-plugin-whitelist
  • onesignal-cordova-plugin

AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.munch_delivery.app" 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" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/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.Black.NoTitleBar" 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>
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id" />
        <meta-data android:name="com.facebook.sdk.ApplicationName" android:value="@string/fb_app_name" />
        <activity android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/fb_app_name" android:name="com.facebook.FacebookActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <amazon:enable-feature android:name="com.amazon.device.messaging" android:required="false" xmlns:amazon="http://schemas.amazon.com/apk/res/android" />
        <service android:exported="false" android:name="com.onesignal.ADMMessageHandler" />
        <receiver android:name="com.onesignal.ADMMessageHandler$Receiver" android:permission="com.amazon.device.messaging.permission.SEND">
            <intent-filter>
                <action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
                <action android:name="com.amazon.device.messaging.intent.RECEIVE" />
                <category android:name="com.munch_delivery.app" />
            </intent-filter>
        </receiver>
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
</manifest>

EDIT:

Managed to find a temporary solution by changing all occurrences of com.facebook.android:facebook-android-sdk:4.+ to com.facebook.android:facebook-android-sdk:4.8.0. Is there any permanent solution to this or is this the right way to go?

回答1:

So this was apparently fixed in the plugin but not yet released

https://github.com/jeduan/cordova-plugin-facebook4/commit/aff9a08a86cc6c6a18019f7adc2896ddf97c11cd

in my package.json I changed

{
  "variables": {
    "APP_ID": "REPLACE_FACEBOOK_APPID",
    "APP_NAME": "REPLACE_FACEBOOK_APPNAME"
  },
  "locator": "cordova-plugin-facebook4@1.6.3",
  "id": "cordova-plugin-facebook4"
},

to

{
  "variables": {
    "APP_ID": "REPLACE_FACEBOOK_APPID",
    "APP_NAME": "REPLACE_FACEBOOK_APPNAME"
  },
  "locator": "https://github.com/jeduan/cordova-plugin-facebook4#aff9a08a86cc6c6a18019f7adc2896ddf97c11cd",
  "id": "cordova-plugin-facebook4"
},

Then you have to remove the old plugin and install the new one. I do it in bash with

cd myproject
rimraf platforms/
rimraf plugins/
ionic state restore

or

cd myproject
cordova plugin rm cordova-plugin-facebook4
ionic state restore


回答2:

For those poor souls looking for a solution for their broken phonegap build apps for this same reason, here's how to use a specific github commit in a plugin declaration in config.xml:

<plugin spec="https://github.com/jeduan/cordova-plugin-facebook4#aff9a08a86cc6c6a18019f7adc2896ddf97c11cd" source="git" >
  <param name="APP_ID" value="YOUR_APP_ID"/>
  <param name="APP_NAME" value="YOUR_APP_NAME"/>
</plugin> 


回答3:

Add string resources into (I am using linux ubuntu this is my ionic project path) file : /home/user/js/fb4/platforms/android/app/src/main/res/values/strings.xml

<string name="fb_app_id">59523234234</string>
<string name="fb_app_name">hajmo.ba</string>

and my project now works!



回答4:

If you have the plugin in a local repo you can replace the following line in the "plugin.xml" file :

<framework src="com.facebook.android:facebook-android-sdk:4.+"/>

by

<framework src="com.facebook.android:facebook-android-sdk:4.8.+"/>

Then remove the facebook-4 plugin from your project before adding it again from your local repo which, now, contains the correction.

or you can follow the suggestion of @jakub.g



回答5:

I didn't have enough reputation to add it as comment, so I am posting it as an answer. I was unable to solve this issue using methods specified by @suprandr and @jakub.g, What worked for me was replacing every occurrence of "com.facebook.android:facebook-android-sdk:4.+" with "com.facebook.android:facebook-android-sdk:4.8.0" in my Cordova project.

NOTE: This is just a temporary fix