"No resource found that matches the given name..:" - Android Studio 2.1.2(React 本机应用程序)

"No resource found that matches the given name..:" - Android Studio 2.1.2 (React Native App)

在为 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'
}

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

更新

模块设置

当我点击 + 添加库时,会弹出以下 window:

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

针对 React Native 应用程序的修复:

你必须运行它通过命令react-native 运行- android 如官方文档所述。

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

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

 <?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"
}

调试此问题的其他方法:

右键单击您的应用程序

打开模块设置

Select 依赖项 选项卡

点击右边的绿色+符号

Select 库依赖

从列表中选择 appcompat-v7

我已经成功地模拟了这个 React Native android 应用程序。

虽然您可以 运行 直接从 Xcode 响应本机 IOS 应用程序, 如果您 运行 直接从 Android Studio 响应本机 Android 应用程序,它似乎不起作用。

必须运行它通过命令react-native 运行-android如文档中所述