【问题标题】:React-native Cant find package android.support.v7.appReact-native 找不到包 android.support.v7.app
【发布时间】:2019-07-17 11:35:31
【问题描述】:

我遇到了这个非常烦人的错误,我无法构建... 它说它找不到包 android.support.v7.app 我的 SplashScreen js 文件中到处都是错误

error: package android.support.v7.app does not exist
import android.support.v7.app.AppCompatActivity;
                             ^
D:\FifaLeagueApp\FifaIL\android\app\src\main\java\com\fifail\SplashActivity.java:7: error: cannot find symbol
public class SplashActivity extends AppCompatActivity {
                                ^

我会提供我的 gradles(我认为问题出在他们身上,但我不知道究竟是什么原因造成的)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.4.2')
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
}

...

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
...
    defaultConfig {
        applicationId "com.fifail"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
 ...

dependencies {
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-restart')
    implementation project(':react-native-gesture-handler')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation "com.facebook.react:react-native:+"  // From node_modules
}
....
}

【问题讨论】:

    标签: android react-native build.gradle


    【解决方案1】:

    终于解决了这个问题,在这里为像我一样来这里寻找解决方案的人发布解决方案:

    只需将导入更改为以下内容:

    干杯

    【讨论】:

      【解决方案2】:

      听起来你已经启用了 AndroidX

      检查你的 android/gradle.properties 并禁用它

      useAndroidX=true
      

      useAndroidX=false
      

      如果启用,它将跳过 appcompat v7

      编辑:如果您需要 AndroidX,请执行我上面提到的操作并将新版本的 appcompat 添加到您的 android/app/build.gradle 中

      implementation 'androidx.appcompat:appcompat:${rootProject.ext.supportLibVersion}'
      

      在 android/build.gradle 上

      supportLibVersion = '1.0.0'
      

      【讨论】:

      • supportLibVersion = "1.0.0" 为什么不supportLibVersion = "28.0.0"
      • 因为它的androidX和版本适用于那个
      • 其他依赖它的库呢
      • 但是,如果您使用的是最新版本的 RN,那么这就是重点,您必须拥有更新的版本。您对我所指的内容有具体问题还是只是假设
      猜你喜欢
      • 1970-01-01
      • 2020-12-08
      • 1970-01-01
      • 2023-01-18
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多