迁移到AndroidX [英] Migration to AndroidX
问题描述
好吧,我开始从一个有多年历史的项目迁移到AndroidX(此后从此一直未动过),但是我在资源和gradle构建方面遇到了问题.我完全被新的名称空间迷住了,我更改了一些名称空间,升级了AndroidStudio告诉我的所有内容,但仍然无法识别项目中的内容.我将把gradle都粘贴到这里,然后将错误放在下面.
Well, I started a migration to AndroidX from a year old project (untouched since then) and I have problems withs the resources and the gradle build. Im completely lost with the new namespaces, I changed some of them, I upgraded all the things AndroidStudio told me, but still not recognizing things on my project. I will paste both gradle here and Ill put the error below.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
错误
Android resource linking failed
Output: C:\Users\Xrless\Desktop\Programing\TN\TM\app\src\main\res\layout\activity_principal.xml:34: error: attribute android:style not found.
error: failed linking file resources.
Command: C:\Users\Xrless\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\cf456f090f0725907522fb6d2bec3322\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
C:\Users\Xrless\AppData\Local\Android\Sdk\platforms\android-28\android.jar\
--manifest\
C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
-o\
C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
-R\
@C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
--auto-add-overlay\
--java\
C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
--custom-package\
com.example.usuario.tm\
-0\
apk\
--output-text-symbols\
C:\Users\Xrless\Desktop\Programing\TN\TM\app\build\intermediates\symbols\debug\R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
推荐答案
您的activity_principal.xml中存在错误.尝试更改:
There is an error in your activity_principal.xml. Try to change:
android:style
android:style
到
样式
还需要添加
android.useAndroidX = true
android.useAndroidX=true
如果要使用androidX库而不是支持库,请
到 gradle.properties 文件中.
to your gradle.properties file if you want to use androidX library instead of Support Library.
这篇关于迁移到AndroidX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!