如何在android studio中将android API 26更改为29 +?

问题描述 投票:0回答:1

如何从API 26更改为29+,尝试在'com.android.support:appcompat-v7:26.1.0', 'com.android.support:design:26.1.0', 'com.android.support.constraint:constraint-layout:1.0.2', 'com.android.support:cardview-v7:26.1.0'的项目结构中对其进行更改时出现错误如果我更新以下插件,我的所有资源文件都会出错。有没有任何方法可以迁移到androidX而无需修改布局文件。我需要从<android.support.constraint.ConstraintLayout>更改代码所有资源文件中的<androidx.constraintlayout.widget.ConstraintLayout>。如何将应用程序上传到需要API 29的Google Play女巫?

这是我的build.gradle

build.gradle(应用程序级别)

apply plugin: 'com.android.application'
android {
    lintOptions{
        checkReleaseBuilds false
        abortOnError false
    }
    compileSdkVersion 29
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "ak.wp.meto"
        minSdkVersion 17
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:cardview-v7:26.1.0'
    //retrofit, gson
    compile 'com.squareup.retrofit2:converter-scalars:2.1.0'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    //firebase
    compile 'com.google.firebase:firebase-core:11.6.0'
    compile 'com.google.firebase:firebase-messaging:11.6.0'
    compile 'com.google.firebase:firebase-ads:11.6.0'
    //glide
    compile 'com.github.bumptech.glide:glide:4.3.1'
    //circular imageview
    compile 'de.hdodenhof:circleimageview:2.1.0'
}
apply plugin: 'com.google.gms.google-services'

build.gradle(项目级别)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我的布局文件activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <include
                layout="@layout/toolbar_main"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <include layout="@layout/content_main" />
        </LinearLayout>
        <android.support.design.widget.NavigationView
            android:id="@+id/navigationView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/white"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/menu_drawer" />
    </android.support.v4.widget.DrawerLayout>
android android-studio android-layout gradle androidx
1个回答
0
投票

为了支持API 29,必须将项目迁移到AndroidX,这是强制性的。由于android X使用不同的库,因此,您需要更改依赖项,还需要对布局文件进行一些更改。

但是Android Studio中有实用程序,可将您的代码迁移到AndroidX。在这种情况下,您不必更改库或布局。

[在Android Studio中的重构下找到“迁移到AndroidX”的选项。

完成后,您将获得非常基本的错误,可以很容易地修复。

© www.soinside.com 2019 - 2024. All rights reserved.