嗯,今天我终于在迁移到 Androidx 之后建立了一个项目(从一年前就停止了)。借助此页面的一些响应,我设法更改了所有命名空间,但要让我的项目 100% 运行,我仍然遇到两个问题。
第一个是设计 View 上的约束布局问题,我看不到我之前做过的任何事情。 第二个问题是一些我还没有更新的导入,Android Studio 仍然标记错误。
第一个问题
第二个问题
为了以防万一,我现在将粘贴我的 gradle:
项目:
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
模块:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.usuario.tm"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test:runner:1.1.0-alpha3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha3', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.gms:google-services:4.1.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
testImplementation 'junit:junit:4.12'
}
}
apply plugin: 'com.android.application'
apply plugin: 'maven'
最佳答案
TabLayout
的正确导入是:
导入 com.google.android.material.tabs.TabLayout
它来自:
实现“com.google.android.material:material:1.0.0”
AppCompatActivity
的正确导入现在是
import androidx.appcompat.app.AppCompatActivity
来自
实现“androidx.appcompat:appcompat:1.0.0”
您还应该检查您的布局 xml。您需要使用命名空间声明约束布局:androidx.constraintlayout.widget.ConstraintLayout
您还应该尝试在此处删除遗留依赖项 implementation 'androidx.legacy:legacy-support-v4:1.0.0'
关于android - 迁移到 Androidx 后设计 View 和导入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52961792/