简体   繁体   中英

How to fix error package android.support.v7 does not exist?

I've been trying to fix the error message for several hours already "package android.support.v7 does not exist"

Came across every topic about this here, but none of them helped me.

I've tried to add this using File > Project Structure. It showed me that 'build.gradle' is syncing with the project. After that I tried to build the project but I still got the same error message again. Also tried to clean the project and delete cache. As I'm writing the newest version of appcampat is v7:26.0.0-alpha1

Also tried to manually add implementation 'com.android.support:appcompat-v7:26.0.0-alpha1' to the build.gradle , but it didnt help.

This is my MainActivity.java

package example.com;
import android.support.v7.ActionBarActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {
    private WebView myWebView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myWebView = (WebView)findViewById(R.id.webView);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        myWebView.loadUrl("https://example.com");
        myWebView.setWebViewClient(new WebViewClient());
    }

    @Override
    public void onBackPressed() {
        if(myWebView.canGoBack()) {
            myWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "example.com"
        minSdkVersion 14
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.13-beta-3'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'
}

Hope this helps you.

Issues you should look at:-

1) Consider Using AppCompatActivity than ActionBarActivity.

2) Update All dependencies to latest Version ( As mentioned above by CommonsWare use newest version for appcompat is 28.0.0 )

3)Look in your at

i) compileSdkVersion => 29

ii) targetSdkVersion => 29

iii) buildtoolsVersion => 29.0.0

That means your are targeting latest android devices (API level 29), But you are still using dependencies from Api level 26. So update libraries and dependencies to latest.

4) If problem persist Please reduce Api level from 29 to 28 and check.

Hope it works for you.

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