Cordova fails to find Theme.AppCompat.Light

2019-06-05 06:10发布

问题:

I've set up a simple Cordova project which should display a splashscreen on Android. To utilize the whole screen I need to get rid of the statusbar by extending Theme.AppCompat.Light. So I set up this styles.xml file and put it into the root folder of the Cordova project.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Full" parent="@style/Theme.AppCompat.Light">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>
</resources>

Cordova's config.xml file is like this:

    <?xml version='1.0' encoding='utf-8'?>
<widget id="com.domain.test" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Test</name>
    <description>
        Just a test
    </description>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <preference name="Fullscreen" value="true" />
    <preference name="Orientation" value="landscape" />
    <splash src="res/screen/android/splashScreen.png" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <icon density="mdpi" src="res/icon/android/mdpi.png" />
        <icon density="hdpi" src="res/icon/android/hdpi.png" />
        <icon density="xhdpi" src="res/icon/android/xhdpi.png" />
        <icon density="xxhdpi" src="res/icon/android/xxhdpi.png" />
        <icon density="xxxhdpi" src="res/icon/android/xxxhdpi.png" />
        <resource-file src="styles.xml" target="app/src/main/res/values/styles.xml" />
    </platform>
    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
        <activity android:label="@string/app_name" android:name=".ActivityName" android:theme="@style/Full" />
    </edit-config>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
    <plugin name="cordova-plugin-fullscreen" spec="^1.2.0" />
    <engine name="android" spec="~7.1.4" />
</widget>

If I try to compile the project I get these errors:

FAILURE: Build failed with an exception.

What went wrong: Execution failed for task ':app:processDebugResources'. Failed to execute aapt

BUILD FAILED in 1s cmd: Command failed with exit code 1 Error output:

error: resource style/Theme.AppCompat.Light (aka com.domain.test:style/Theme.AppCompat.Light) not found.

error: failed linking references.

回答1:

You possibly didn't add the AppCompat library to your project. Did you add the following line to your configuration files?

<framework src="com.android.support:appcompat-v7:+"/>

Read more about the frameworks here: https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html