简体   繁体   中英

React-native Cant find package android.support.v7.app

I'm having this really annoying error that wont let me build... It says it cant find the package android.support.v7.app With errors all over my SplashScreen js file

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 {
                                ^

I'll provide my gradles (I think the problem coming from them but I cant figure what exactly causing it)

// 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
}
....
}

sounds like you have enabled AndroidX

check your android/gradle.properties and disable this

useAndroidX=true

to

useAndroidX=false

If this is enabled it skips appcompat v7

EDIT: if you need AndroidX do what i mentioned above and add to your android/app/build.gradle a new version of appcompat

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

and on android/build.gradle

supportLibVersion = '1.0.0'

Finally fixed the issue, posting solution here for the ones who came here looking for the solution like me:

Just change the imports to following: 在此处输入图片说明

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM