Android Studio 在不可编辑的 XML 文件上给我显示 AAPT 错误。

huangapple go评论77阅读模式
英文:

Android Studio is giving me AAPT error on uneditable XML files

问题

我正在尝试在Android Studio中设置OpenCV,但无论何时尝试构建我的项目,都会出现以下错误:

/home/oliver/AndroidStudioProjects/Opencvreal/app/build/intermediates
/packaged_manifests/debug/AndroidManifest.xml:33: AAPT: error: 
resource style/AppTheme (aka com.example.opencvreal:style/AppTheme) not found.

错误位于生成的XML文件中,据我了解,该文件是不可编辑的。以下是主要的和生成的XML文件内容:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="opencv.codeonion.com.opencv_test">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        >
        <activity
            android:name=".MainActivity_show_camera"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <supports-screens   android:resizeable="true"
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:anyDensity="true" />

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>

</manifest>
英文:

I am trying to set up OpenCV in android studio but whenever I try to build my project I get this error

/home/oliver/AndroidStudioProjects/Opencvreal/app/build/intermediates
/packaged_manifests/debug/AndroidManifest.xml:33: AAPT: error: 
resource style/AppTheme (aka com.example.opencvreal:style/AppTheme) not found.

The error is with the generated XML file which from my understanding is uneditable. Here is the main and generated XML files

&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;opencv.codeonion.com.opencv_test&quot;&gt;

    &lt;application
        android:allowBackup=&quot;true&quot;
        android:icon=&quot;@mipmap/ic_launcher&quot;
        android:label=&quot;@string/app_name&quot;
        android:supportsRtl=&quot;true&quot;
        android:theme=&quot;@style/AppTheme&quot;
        &gt;
        &lt;activity
            android:name=&quot;.MainActivity_show_camera&quot;
            android:label=&quot;@string/app_name&quot;
            android:theme=&quot;@style/AppTheme.NoActionBar&quot;
            android:screenOrientation=&quot;portrait&quot;&gt;
            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;

                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

    &lt;supports-screens   android:resizeable=&quot;true&quot;
        android:smallScreens=&quot;true&quot;
        android:normalScreens=&quot;true&quot;
        android:largeScreens=&quot;true&quot;
        android:anyDensity=&quot;true&quot; /&gt;

    &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot;/&gt;
    &lt;uses-feature android:name=&quot;android.hardware.camera&quot; android:required=&quot;false&quot;/&gt;
    &lt;uses-feature android:name=&quot;android.hardware.camera.autofocus&quot; android:required=&quot;false&quot;/&gt;
    &lt;uses-feature android:name=&quot;android.hardware.camera.front&quot; android:required=&quot;false&quot;/&gt;
    &lt;uses-feature android:name=&quot;android.hardware.camera.front.autofocus&quot; android:required=&quot;false&quot;/&gt;

&lt;/manifest&gt;

答案1

得分: 2

在你的 app > main > res > values > styles.xml 文件中,请确保存在样式名称为 "AppTheme"。如果已经存在,请尝试清理并重新构建你的项目,希望这能解决问题。

<!-- 应用的基本主题样式。 -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- 在这里定制你的主题。 -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
英文:

In your app > main > res > values > styles.xml make sure style name="AppTheme" is there. If already there then clean and rebuild your project hopefully this will work.

   &lt;!-- Base application theme. --&gt;
    &lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.AppCompat.Light.DarkActionBar&quot;&gt;
        &lt;!-- Customize your theme here. --&gt;
        &lt;item name=&quot;colorPrimary&quot;&gt;@color/colorPrimary&lt;/item&gt;
        &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/colorPrimaryDark&lt;/item&gt;
        &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAccent&lt;/item&gt;
    &lt;/style&gt;

huangapple
  • 本文由 发表于 2020年10月24日 07:18:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/64508390.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定