在模块 objectbox-android-2.9.1-runtime 中发现重复 class io.objectbox.android.AndroidObjectBrowser

Duplicate class io.objectbox.android.AndroidObjectBrowser found in modules objectbox-android-2.9.1-runtime

我正在 Kotlin 中使用 ObjectBox DB,并希望将 DataBrowser 用于 documentation 中所示的 ObjectBox。在我对 build.gradle 和清单进行更改之前,该项目已经 运行 了。现在,它给出了这样的错误:

> 失败:构建完成但有 2 次失败。

1: 任务因异常而失败。

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable Duplicate class io.objectbox.android.AndroidObjectBrowser found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1) Duplicate class io.objectbox.android.AndroidScheduler found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1) Duplicate class io.objectbox.android.AndroidScheduler$Runner found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1) Duplicate class io.objectbox.android.BuildConfig found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1) Duplicate class io.objectbox.android.ObjectBoxDataSource found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1) Duplicate class io.objectbox.android.ObjectBoxDataSource found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1) Duplicate class io.objectbox.android.ObjectBoxDataSource$Factory found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1) Duplicate class io.objectbox.android.ObjectBoxLiveData found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1) Duplicate class io.objectbox.android.ObjectBoxLiveData found in modules objectbox-android-2.9.1-runtime (io.objectbox:objectbox-android:2.9.1) and objectbox-android-objectbrowser-2.9.1-runtime (io.objectbox:objectbox-android-objectbrowser:2.9.1)

 Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

2: 任务因异常而失败。

A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction 2 files found with path 'lib/armeabi-v7a/libobjectbox-jni.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/r/tools/jniLibs-vs-imported-targets

57 秒后构建失败 17 个可操作任务:7 个已执行,10 个已更新

之前 (gradle)

 plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'io.objectbox'
}

android {
    compileSdkVersion 30

    defaultConfig {
        applicationId "com.example.projectnamehere"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation "io.objectbox:objectbox-android:2.9.1"
    implementation "io.objectbox:objectbox-kotlin:2.9.1"

}

在 (gradle)

之后
    plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt' // Only for Kotlin projects.
}

android {
    compileSdkVersion 30

    defaultConfig {
        applicationId "com.example.projectnamehere"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation "io.objectbox:objectbox-android:2.9.1"
    implementation "io.objectbox:objectbox-kotlin:2.9.1"
    debugImplementation "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
    releaseImplementation "io.objectbox:objectbox-android:$objectboxVersion"

}
apply plugin: 'io.objectbox'

之前(清单)

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.projectnamehere">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.ThemeHere">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

之后(清单)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.projectnamehere">
    <!-- Required to provide the web interface -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Required to run keep-alive service when targeting API 28 or higher -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.ThereHere">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

在 build.gradle 文件中,有两个相同的 类 是使用相同的库但不同的关键字实现的 releaseImplementation“io.objectbox:objectbox-android:$objectboxVersion” 实现“io.objectbox:objectbox-android:2.9.1”