英文:
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
<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>
答案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.
   <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论