【问题标题】:"No resource found that matches the given name..:" - Android Studio 2.1.2 (React Native App)“找不到与给定名称匹配的资源......:” - Android Studio 2.1.2(React Native App)
【发布时间】:2016-10-13 10:44:14
【问题描述】:

在为 ios 开发了 react native 应用程序之后,我还想在 android 上对其进行测试。

按照文档中的步骤并设置 Android Studio 进行测试后,我很遗憾无法运行该应用程序,因为以下错误我似乎没有找到合适的解决方案。尽管之前有人问过类似的问题。

错误:

Error:(6, -1) Android Resource Packaging: [ios_ver] /path/ios_ver/android/app/src/main/AndroidManifest.xml:6: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name').
Error:(6, -1) Android Resource Packaging: [ios_ver] /path/ios_ver/android/app/src/main/AndroidManifest.xml:6: error: Error: No resource found that matches the given name (at 'icon' with value '@mipmap/ic_launcher').
Error:(6, -1) Android Resource Packaging: [ios_ver] /path/ios_ver/android/app/src/main/AndroidManifest.xml:6: error: Error: No resource found that matches the given name (at 'theme' with value '@style/AppTheme').
Error:(11, -1) Android Resource Packaging: [ios_ver] /path/ios_ver/android/app/src/main/AndroidManifest.xml:11: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name').

我问了一个 Android 开发者。我的朋友,但他只说他不需要编辑清单文件,也没有类似的问题。

我的清单文件:

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

    <application
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
        android:debuggable="true"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>
</manifest>

build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile


apply from: "../../node_modules/react-native/react.gradle"


def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 21
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.ios_ver"
        minSdkVersion 21
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    compile project(':react-native-fs')
    compile project(':react-native-image-picker')
    compile project(':react-native-mail')
    compile project(':react-native-camera')
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
  from configurations.compile
  into 'libs'
}

我很乐意听取您的任何解决方案。 感谢您的帮助。

更新

模块设置

当我单击 + 添加库时,会弹出以下窗口:

不幸的是,我没有看到任何可以从中选择 appcompat-v7 的库列表。

【问题讨论】:

    标签: android android-studio react-native android-studio-2.1


    【解决方案1】:

    修复 React Native 应用程序:

    您必须按照官方文档中的说明通过命令 react-native run-android 运行它。

    如果您不使用 React Native,请修复:

    您的Android Manifest 文件缺少运行您的应用程序所需的一些内容。其中大部分都在&lt;application &lt;/application&gt; 标签下。下面是一个示例,您可以使用它来修复您的问题:

     <?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.prad.myapplication">
    
         <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"
                 android:label="@string/app_name"
                 android:theme="@style/AppTheme.NoActionBar">
                 <intent-filter>
                     <action android:name="android.intent.action.MAIN"/>
                     <category android:name="android.intent.category.LAUNCHER"/>
                 </intent-filter>
             </activity>
        </application>
     </manifest>
    

    将您的清单与上述清单进行比较后,请尝试以下操作:

    检查字符串资源:

    路径: res/values/strings.xml

    <string name="app_name">"MyFirstApp"</string>
    

    查看样式资源:

    路径: res/values/styles

    The.AppCompat.Light.DarkActionBar 更改为 Theme.Light

     <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    

    检查 build.gradle

    buildToolsVersion "23.0.1" 更改为buildToolsVersion "21.1.1"

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.1"
    
        defaultConfig {
            minSdkVersion 21 
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
    }
    

    调试此问题的其他方法:

    右击你的应用

    打开模块设置

    选择依赖项选项卡

    点击右侧的绿色+符号

    选择库依赖

    从列表中选择 appcompat-v7

    【讨论】:

    • 您在活动下编写的一些内容正在我的代码中应用。这有关系吗?我已经尝试了您的代码并用我的代码替换了条目,但仍然出现相同的错误:/
    • 当然。更新了我的问题!我的 res/values/strings.xml 的定义也如您的答案所示:)
    • 谢谢或更新的答案,不幸的是我仍然收到同样的错误
    • 你能发布你的 build.gradle 文件吗?我们也进去看看吧。
    • 用 build.gradle 文件更新了我的问题 :)
    【解决方案2】:

    我已经设法模拟了这个 react native android 应用程序。

    虽然您可以直接从 Xcode 运行您的 react 原生 IOS 应用程序, 如果你直接从 Android Studio 运行你的 react native Android App 似乎是行不通的。

    必须按照文档中的说明通过命令 react-native run-android 运行它

    【讨论】:

      猜你喜欢
      • 2017-11-27
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 2018-05-25
      • 1970-01-01
      相关资源
      最近更新 更多