我已经尝试修复错误消息已有几个小时了,“包android.support.v7不存在”
在这里涉及到有关此主题的每个主题,但没有一个对我有帮助。
我尝试使用文件>项目结构来添加它。它告诉我“ 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'
}
答案 0 :(得分:0)
希望这对您有所帮助。
问题,您应该看一下:-
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,然后进行检查。
希望它对您有用。