![](/img/trans.png)
[英]How to fix "error: package android.support.v7.widget does not exist" problem?
[英]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.