![](/img/trans.png)
[英]Build Fail with 'com.android.tools.r8.utils.AbortException: Error: Program type already present: com.google.firebase.FirebaseApp'
[英]Program type already present: use of androidx library with firebase and google play service fail to build android studio 3.1.1
我在APK构建中面临以下冲突
Program type already present: android.support.v4.media.MediaBrowserCompat$CallbackHandler
Message{kind=ERROR, text=Program type already present: android.support.v4.media.MediaBrowserCompat$CallbackHandler, sources=[Unknown source file], tool name=Optional.of(D8)}
下面是我的应用程序gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.himotech"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled true
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
lintOptions {
abortOnError false
}
realm {
syncEnabled = false;
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.0'
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'
}
apply plugin: 'com.google.gms.google-services'
下面是项目gradle文件
buildscript {
ext.kotlin_version = '1.2.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:5.4.1"
classpath 'com.google.gms:google-services:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
ext{
// The following are only a few examples of the types of properties you can define.
compileSdkVersion = 27
// You can also create properties to specify versions for dependencies.
// Having consistent versions between modules can avoid conflicts with behavior.
supportLibVersion = '27.1.1'
firebaseCoreVersion='16.0.3'
firebaseDatabaseVersion='16.0.2'
firebaseLibVersion='15.1.0'
firebaseMessaging='17.3.1'
}
在gradle属性中,我已启用androidx使用:
android.useAndroidX = true
android.enableJetifier = false
我没有经历这一SO ,但仍然没能解决问题。
注意: 如果我从gradle中删除数据绑定,那么它工作正常。
我看到你的手提包里有一堆过期的物品。
您需要将Android Studio移至3.2。 (稳定
另外,您的kotlin版本应为1.2.70+(请勿使用1.2.71),并且存在错误。 严重地,这将导致Android Studio冻结很多。
您的Gradle构建工具也应在3.2.0+范围内。
确保打包在gradle-wrapper.properties中的发行版的DistributionUrl为4.10-all或更高版本
您的jre依赖关系应删除为赞成或jdk依赖关系
您的jre版本是7,应该更新到8。
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
如果可以,请在约束布局上输入2.0.0-alpha2。 虽然不是必需的。
截至发布之日androidx当前依赖项的示例。
//Android Google Libraries
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation "androidx.constraintlayout:constraintlayout:2.0.0-alpha2"
听起来也像您曾经使用过的一样,但请确认您具有gradle.properties
android.enableJetifier=true
android.useAndroidX=true
jetifier将尝试使您的依赖项与androidX兼容。 最后,如果您遇到了太多问题,请更新androidX,然后取消更改,并从版本控制处进行编译。 然后使用3.2中的迁移工具。 它做得很好,只留下了一些小错误以进行清理。
同样值得注意的是,您可能必须转到每个xml文件并确认正确引用了新的命名空间,例如RecyclerView应该在xml中显示新的androidx命名空间。 在代码中引用它们时相同。
最近,我将所有项目都更新为androidX,第一个项目进行了一些试验和错误,第二个项目使用了迁移工具,这使我的生活更加顺利。
删除数据绑定对您有用的原因是,它试图在数据绑定生成的文件中构建“不正确的名称空间”对象。 您需要检查并修复每个xml文件,以便在Android小部件和Framework元素上使用正确的名称空间。
我将提供一个抽屉活动的示例。
<data>
<variable name="activity" type="com.a35.activities.MainActivity"/>
<variable name="iBindingRecyclerView" type="com.a35.interfaces.IBindingRecyclerView"/>
</data>
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--TOP TOOLBAR-->
<include
android:id="@+id/toolbarMain"
layout="@layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!--TOP BLACK LINE-->
<View
android:id="@+id/vRedLine"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_2"
android:background="@color/black" />
<!-- FrameLayout is used to insert fragments to display -->
<FrameLayout
android:id="@+id/fragPlaceholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="@color/colorPrimary">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/nav_drawer_header"
android:id="@+id/navHeader"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lstMenuItems"
android:layout_below="@+id/navHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:bindRcvInterface="@{iBindingRecyclerView}"
app:bindRcvList="@{activity.getDrawerItemList}"/>
<ImageView
android:id="@+id/imgBottomLogo"
android:layout_width="@dimen/dp_160"
android:layout_height="@dimen/dp_35"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/dp_35"
android:src="@drawable/my_logo" />
</RelativeLayout>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.