我已经将我的 Android Studio 和 targetSdkVersion
(build.gradle)升级到了29。我迁移到了 AndroidX。现在,Gradle 的构建给了我两个错误:
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
检测到以下 AndroidX 依赖项: AndroidX。Version edparcelable: version edparcelable: 1.0.0,androidx.片段: 片段: 1.0.0,androidx。滑动面板布局: 滑动面板布局: 1.0.0,androidx。Core: core: 1.0.0,androidx.Customview: customview: 1.0.0,androidx.刷新版面: 刷新版面: 1.0.0,androidx。插值器: 插值器: 1.0.0,androidx。加载程序: 加载程序: 1.0.0,androidx。抽屉布局: 抽屉布局: 1.0.0,androidx。Viewpager: 1.0.0,androidx.Collection: Collection: 1.0.0,androidx.LocalBroadcasting Manager: 1.0.0,androidx.生命周期: 生命周期-通用: 2.0.0,androidx。拱门。Core: core-common: 2.0.0,androidx.注释: 注释: 1.1.0,androidx。生命周期: 生命周期-实时数据: 2.0.0,androidx。遗留: Heritage-support-core-ui: 1.0.0,androidx。生命周期: 生命周期-视图模型: 2.0.0,androidx。生命周期: 生命周期-实时数据-核心: 2.0.0,androidx。拱门。Core: core-run: 2.0.0,androidx.遗留: Heritage-support-core-utils: 1.0.0,androidx。Documentfile: documentfile: 1.0.0,androidx.CursorAdapter: cursorAdapter: 1.0.0,androidx.生命周期: 生命周期-运行时: 2.0.0,androidx。布局: 1.0.0,androidx。1.0.0,androidx.Print: 1.0.0
我的代码是:
package it.manuel.myapp;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.DownloadListener;
import android.webkit.URLUtil;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
import com.google.firebase.messaging.FirebaseMessaging;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://google.com/");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "it.manuel.myapp"
minSdkVersion 29
targetSdkVersion 29
versionCode 2
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
buildToolsVersion = '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-core:17.2.3'
implementation 'com.google.firebase:firebase-messaging:20.1.1'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
为什么不能用了?