Rah*_*ogi 90 android android-studio android-design-library android-9.0-pie
我已经成功配置了android-P SDK环境.当我尝试使用android设计支持库时,我面临项目构建错误.项目配置是:
IDE:3.2 Canary 17目标API:28编译API:28
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.app.navigationpoc"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'com.android.support:design:28.0.0-alpha3'
implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}
Run Code Online (Sandbox Code Playgroud)
并且构建失败的错误是:
清单合并失败:来自[androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86的属性应用程序@ appComponentFactory值=(androidx.core.app.CoreComponentFactory)也出现在[com.android] .support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91 value =(android.support.v4.app.CoreComponentFactory).建议:在AndroidManifest.xml:6:5-40:19中添加'tools:replace ="android:appComponentFactory"'来覆盖.
小智 74
您既可以使用先前的API包版本的工件,也可以使用新的Androidx,而不是两者.
如果您想使用以前的版本,请用您的依赖项替换
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0-alpha3'
implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}
Run Code Online (Sandbox Code Playgroud)
如果你想使用Androidx:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'com.google.android.material:material:1.0.0-alpha3'
implementation 'androidx.cardview:cardview:1.0.0-alpha3'
}
Run Code Online (Sandbox Code Playgroud)
Khe*_*raj 53
Android之后不会更新支持库28.0.0.
这将是android.support包装下的最后一个功能版本,鼓励开发人员迁移到AndroidX 1.0.0.
所以使用库AndroidX.
androidx或任何库,因为alpha,beta,rc可能存在您不希望随应用程序提供的错误.在你的情况下
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
}
Run Code Online (Sandbox Code Playgroud)
Car*_*ago 40
添加这个:
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Run Code Online (Sandbox Code Playgroud)
到您的清单应用程序
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString">
Run Code Online (Sandbox Code Playgroud)
希望它能够解决
Dou*_*ita 16
我用过那个选项:
使用Android Studio 3.2及更高版本,您可以通过从菜单栏中选择Refactor> Migrate to AndroidX,快速迁移现有项目以使用AndroidX.
https://developer.android.com/jetpack/androidx/migrate
1.将这些代码添加到app/build.gradle:
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:26.1.0' // the lib is old dependencies version;
}
Run Code Online (Sandbox Code Playgroud)
2.修改了sdk和工具版本到28:
compileSdkVersion 28
buildToolsVersion '28.0.3'
targetSdkVersion 28
Run Code Online (Sandbox Code Playgroud)
2.在AndroidManifest.xml文件中,您应该添加两行:
<application
android:name=".YourApplication"
android:appComponentFactory="anystrings be placeholder"
tools:replace="android:appComponentFactory"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
Run Code Online (Sandbox Code Playgroud)
感谢@Carlos Santiago的答案: API 28(P)的Android设计支持库无效
打开文件 gradle.properties 并向其中添加以下两行:
android.useAndroidX = true
android.enableJetifier = true
Run Code Online (Sandbox Code Playgroud)
清理和构建
Google引入了新的AndroidX依赖项。您需要迁移到AndroidX,这很简单。
我将所有依赖项替换为AndroidX依赖项
旧设计依赖
implementation 'com.android.support:design:28.0.0'
Run Code Online (Sandbox Code Playgroud)
新的AndroidX设计依赖项
implementation 'com.google.android.material:material:1.0.0-rc01'
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到AndroidX依赖项 https://developer.android.com/jetpack/androidx/migrate
自动AndroidX迁移选项(在Android Studio 3.3及更高版本中受支持)
通过从菜单栏中选择“重构”>“迁移到AndroidX”,可以迁移现有项目以使用AndroidX。
首先,您应该查看gradle.properties并且这些值必须为true。如果你看不到它们,你必须写下来。
android.useAndroidX = true
android.enableJetifier = true
Run Code Online (Sandbox Code Playgroud)
之后,您可以在build.gradle (Module: app) 中使用 AndroidX 依赖项。此外,您必须检查compileSDKVersion和targetVersion。它们应该至少为 28。例如,我使用的是 29。
因此,一个 androidx 依赖示例:
implementation 'androidx.cardview:cardview:1.0.0'
Run Code Online (Sandbox Code Playgroud)
但是要小心,因为一切都不是像cardview 依赖那样 以androidx开头。例如,旧的设计 依赖是:
implementation 'com.android.support:design:27.1.1'
Run Code Online (Sandbox Code Playgroud)
但是新的设计 依赖是:
implementation 'com.google.android.material:material:1.3.0'
Run Code Online (Sandbox Code Playgroud)
RecyclerView 是:
implementation 'androidx.recyclerview:recyclerview:1.1.0'
Run Code Online (Sandbox Code Playgroud)
因此,您必须仔细搜索和阅读。
我通过将所有androidx.*内容替换为 来克服这种情况appropiate package name。
改变你的线路
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
Run Code Online (Sandbox Code Playgroud)
到
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Run Code Online (Sandbox Code Playgroud)
著名的
tools:replace="android:appComponentFactory"从 AndroidManifest 中删除 | 归档时间: |
|
| 查看次数: |
148292 次 |
| 最近记录: |