繁体   English   中英

如何修复错误包android.support.v7不存在?

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

我一直在尝试修复错误消息几个小时已经“包android.support.v7不存在”

在这里遇到了关于这个的每个主题,但没有一个帮助我。

我试图使用File> Project Structure添加它。 它告诉我'build.gradle'正在与项目同步。 之后,我尝试构建项目,但我仍然得到相同的错误消息。 还尝试清理项目并删除缓存。 正在我写的最新版本的appcampat是v7:26.0.0-alpha1

还尝试手动将implementation 'com.android.support:appcompat-v7:26.0.0-alpha1'添加到build.gradle ,但它没有帮助。

这是我的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文件

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

希望这对你有所帮助。

你应该看看的问题: -

1)考虑使用AppCompatActivity而不是ActionBarActivity。

2)更新所有依赖关系到最新版本(如上所述CommonsWare使用appcompat的最新版本是28.0.0)

3)看看你的

i)compileSdkVersion => 29

ii)targetSdkVersion => 29

iii)buildtoolsVersion => 29.0.0

这意味着您的目标是最新的Android设备(API级别29),但您仍然使用Api级别26的依赖项。因此,将库和依赖项更新为最新版本。

4)如果问题仍然存在请将Api水平从29降低到28并检查。

希望对你有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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