AndroidManifest.xml无法正确编译

时间:2015-07-25 17:36:06

标签: java android xml manifest

我遇到了Android Manifest文件的问题。我在网上关注一个例子,像往常一样,代码中有错误。我已修复所有与java相关的错误,但Android Manifest文件有一些我不熟悉的。

以下是代码:

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dji.FPVDemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <uses-feature android:name="android.hardware.usb.accessory" android:required="false" />
    <uses-feature android:name="android.hardware.usb.host" android:required="false" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <uses-library android:name="com.android.future.usb.accessory" />

        <meta-data
            android:name="com.dji.sdk.API_KEY"
            android:value="" />

        <activity
            android:name=".\DJIAoaActivity"
            android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
            android:screenOrientation="sensorLandscape" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
            </intent-filter>
        </activity>

        <activity
            android:name=".FPVActivity"
            android:label="@string/app_name" >
        </activity>

    </application>

</manifest>

以下是错误:

Error:(18, -1) Android Resource Packaging: [FPVDemo] C:\Users\Jesse\Desktop\Android-FPVDemo-Part1-master\FPVDemo\bin\AndroidManifest.xml:18: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name').
Error:(18, -1) Android Resource Packaging: [FPVDemo] C:\Users\Jesse\Desktop\Android-FPVDemo-Part1-master\FPVDemo\bin\AndroidManifest.xml:18: error: Error: No resource found that matches the given name (at 'theme' with value '@style/AppTheme').
Error:(45, -1) Android Resource Packaging: [FPVDemo] C:\Users\Jesse\Desktop\Android-FPVDemo-Part1-master\FPVDemo\bin\AndroidManifest.xml:45: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name').
Error:(18, -1) Android Resource Packaging: [FPVDemo] C:\Users\Jesse\Desktop\Android-FPVDemo-Part1-master\FPVDemo\bin\AndroidManifest.xml:18: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_launcher').

我认为错误位于GUI组件未正确命名的部分,但我可能错了。我想知道你们对它的看法。也许我错过了一些简单的事情。

3 个答案:

答案 0 :(得分:1)

检查是否已创建strings.xml文件,以及app_name的键值对。或者只是尝试在标签中给出值,例如

android:label =&#34;我的应用&#34;

答案 1 :(得分:1)

此错误,因为您的项目没有res文件夹

res文件夹在Eclipse和Android Studio中不同

  

中的资源文件夹      

Eclipse »*[project]/res*

     

Android Studio »*[module]/src/main/res*

图片中的

可以看到

res folder

»了解更多信息Android Studio vs Eclipse folder structure

例如在 Eclipse

res

发生此错误

Error:(18, -1) Android Resource Packaging: [FPVDemo] C:\Users\Jesse\Desktop\Android-FPVDemo-Part1-master\FPVDemo\bin\AndroidManifest.xml:18: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name').

在res / values文件夹中创建string.xml并添加

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">YOUR APP NAME</string>

</resources>

发生此错误

Error:(18, -1) Android Resource Packaging: [FPVDemo] C:\Users\Jesse\Desktop\Android-FPVDemo-Part1-master\FPVDemo\bin\AndroidManifest.xml:18: error: Error: No resource found that matches the given name (at 'theme' with value '@style/AppTheme').

在res / values文件夹中创建style.xml并添加

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

发生此错误

Error:(18, -1) Android Resource Packaging: [FPVDemo] C:\Users\Jesse\Desktop\Android-FPVDemo-Part1-master\FPVDemo\bin\AndroidManifest.xml:18: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_launcher').

在res / drawable-hdpi文件夹中复制您的应用图标

如果使用 Android Studio ,您可以访问此链接以获取更多信息»https://developer.android.com/tools/projects/index.html

答案 2 :(得分:0)

问题在于您的res/values/strings.xml文件没有<string> app_name。主题和启动器图标也是如此。确保这些资源可用,然后重新构建您的项目。