ich*_*urs 1 java android gradle firebase google-cloud-firestore
最近将 Firebase-Firestore 添加到我的 android 项目中,并在构建时开始获取对 protobuf 中的类的重复引用。
\n\nbuild.gradle
// Top-level build file where you can add configuration options common to all\n// sub-projects/modules.\n\nbuildscript {\n\n ext.protobufVersion = \'0.8.6\'\n\n repositories {\n google()\n jcenter()\n maven { url \'https://maven.fabric.io/public\' }\n maven { url "https://jcenter.bintray.com" }\n maven { url "https://jitpack.io" }\n }\n dependencies {\n classpath \'com.android.tools.build:gradle:3.5.3\'\n classpath \'io.fabric.tools:gradle:1.31.2\'\n classpath \'com.google.gms:google-services:4.3.3\'\n classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.41"\n classpath \'com.akaita.android:easylauncher:1.3.1\'\n classpath "com.google.protobuf:protobuf-gradle-plugin:$protobufVersion"\n }\n}\n\napply plugin: \'com.android.application\'\napply plugin: \'io.fabric\'\napply plugin: \'com.google.gms.google-services\'\napply plugin: \'kotlin-android\'\napply plugin: \'kotlin-kapt\'\napply plugin: \'com.akaita.android.easylauncher\'\napply plugin: \'com.google.protobuf\'\n\nrepositories {\n google()\n jcenter()\n mavenCentral()\n maven { url \'https://jitpack.io\' }\n maven { url \'https://maven.fabric.io/public\' }\n}\n\nconfigurations {\n playstoreImplementation\n compatImplementation\n freeCompatImplementation\n stagingCompatImplementation\n}\n\next {\n supportLibVersion = \'28.0.0\'\n}\n\ndependencies {\n implementation \'androidx.constraintlayout:constraintlayout:2.0.0-beta2\'\n /*playstoreImplementation(\'com.google.firebase:firebase-messaging:15.0.2\') {\n exclude group: \'com.google.firebase\', module: \'firebase-core\'\n }*/\n compatImplementation \'androidx.emoji:emoji-appcompat:1.0.0\'\n freeCompatImplementation \'androidx.emoji:emoji-bundled:1.0.0\'\n stagingCompatImplementation \'androidx.emoji:emoji-bundled:1.0.0\'\n implementation \'androidx.legacy:legacy-support-v4:1.0.0\'\n implementation \'org.sufficientlysecure:openpgp-api:10.0\'\n implementation \'com.github.inputmice:Android-Image-Cropper:2.7.2\'\n implementation \'androidx.legacy:legacy-support-v13:1.0.0\'\n implementation \'androidx.appcompat:appcompat:1.1.0-rc01\'\n implementation \'androidx.cardview:cardview:1.0.0\'\n implementation \'androidx.legacy:legacy-support-v4:1.0.0\'\n implementation \'androidx.emoji:emoji:1.0.0\'\n implementation \'com.google.android.material:material:1.1.0-alpha07\'\n implementation \'org.bouncycastle:bcmail-jdk15on:1.58\'\n implementation \'org.whispersystems:signal-protocol-java:2.6.2\'\n implementation \'org.conscrypt:conscrypt-android:1.3.0\'\n\n implementation \'rocks.xmpp:xmpp-addr:0.8.0\'\n implementation \'org.osmdroid:osmdroid-android:6.0.1\'\n implementation \'de.measite.minidns:minidns-hla:0.2.4\'\n implementation \'me.leolin:ShortcutBadger:1.1.22@aar\'\n implementation \'com.makeramen:roundedimageview:2.3.0\'\n implementation \'com.wefika:flowlayout:0.4.1\'\n implementation \'net.ypresto.androidtranscoder:android-transcoder:0.2.0\'\n\n implementation \'org.hsluv:hsluv:0.2\'\n //Butterknife dependency\n implementation \'com.jakewharton:butterknife:10.2.0\'\n kapt \'com.jakewharton:butterknife-compiler:10.2.0\'\n //Network Retrofit and okhttp\n implementation(\'com.squareup.retrofit2:retrofit:2.1.0\') {\n // exclude Retrofit\xe2\x80\x99s OkHttp dependency module and define your own module import\n exclude module: \'okhttp\'\n }\n implementation \'com.google.code.gson:gson:2.8.5\'\n implementation \'com.squareup.retrofit2:converter-gson:2.4.0\'\n implementation \'com.squareup.okhttp3:logging-interceptor:3.9.0\'\n implementation \'com.squareup.okhttp3:okhttp:3.10.0\'\n implementation \'androidx.multidex:multidex:2.0.1\'\n implementation \'com.hbb20:ccp:2.2.3\'\n implementation \'com.crashlytics.sdk.android:crashlytics:2.10.1\'\n implementation \'com.crashlytics.sdk.android:answers:1.4.7\'\n implementation \'com.google.firebase:firebase-core:17.2.1\'\n implementation \'com.google.firebase:firebase-messaging:20.1.0\'\n implementation \'com.google.firebase:firebase-config:19.1.0\'\n implementation \'com.google.firebase:firebase-dynamic-links:19.0.0\'\n implementation \'com.google.firebase:firebase-database:19.2.0\'\n implementation \'com.google.firebase:firebase-firestore:21.3.1\'\n implementation \'com.wdullaer:swipeactionadapter:2.0.0\'\n implementation \'com.wdullaer:materialdatetimepicker:3.2.0\'\n implementation \'io.michaelrocks:libphonenumber-android:8.10.1\'\n implementation \'com.google.code.gson:gson:2.8.5\'\n implementation \'ch.halcyon:squareprogressbar:1.6.4\'\n implementation \'com.github.zawadz88:material-activity-chooser:0.2.2\'\n implementation \'com.urbanairship.android:urbanairship-fcm:11.0.1\'\n implementation \'commons-codec:commons-codec:1.12\'\n implementation \'com.github.kal72:RackMonthPicker:1.6.0\'\n implementation "android.arch.work:work-runtime:1.0.0-alpha11"\n implementation \'org.apache.commons:commons-lang3:3.9\'\n implementation \'org.greenrobot:eventbus:3.1.1\'\n implementation \'com.google.android.play:core:1.6.4\'\n implementation \'com.google.protobuf:protobuf-lite:3.0.1\'\n\n\n //What\'s new library\n implementation(\'io.github.tonnyl:whatsnew:0.1.2\') {\n exclude module: \'annotations\'\n }\n\n //Showcase view library\n implementation \'com.github.amlcurran.showcaseview:library:5.4.3\'\n\n implementation \'com.squareup.picasso:picasso:2.71828\'\n implementation \'com.mikhaellopez:circularimageview:3.2.0\'\n implementation \'com.facebook.fresco:fresco:2.0.0\'\n implementation files(\'libs/YouTubeAndroidPlayerApi.jar\')\n //firebase analytics\n implementation \'com.google.firebase:firebase-analytics:17.2.0\'\n\n //https://jitpack.io/p/kapilmhr/AlphabetIndexFastScrollRecyclerview\n implementation \'com.github.kapilmhr:AlphabetIndexFastScrollRecyclerview:1.0.0\'\n\n}\n\next {\n travisBuild = System.getenv("TRAVIS") == "true"\n preDexEnabled = System.getProperty("pre-dex", "true")\n}\n\nandroid {\n compileSdkVersion 28\n\n signingConfigs {\n company{\n {...}\n }\n }\n\n defaultConfig {\n minSdkVersion 21\n targetSdkVersion 28\n versionCode 120\n versionName "2.10.3"\n archivesBaseName += "-$versionName"\n applicationId "com.company.chat"\n resValue "string", "applicationId", applicationId\n resValue "string", "app_name", "Company"\n multiDexEnabled true\n vectorDrawables {\n useSupportLibrary = true\n }\n }\n\n dataBinding {\n enabled true\n }\n\n dexOptions {\n // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.\n preDexLibraries = preDexEnabled && !travisBuild\n jumboMode true\n javaMaxHeapSize "2g"\n\n }\n\n compileOptions {\n sourceCompatibility JavaVersion.VERSION_1_8\n targetCompatibility JavaVersion.VERSION_1_8\n }\n\n flavorDimensions("distribution", "emoji")\n\n productFlavors {\n /*playstore {\n dimension "distribution"\n versionNameSuffix "+p"\n }*/\n free {\n dimension "distribution"\n {...}\n\n }\n staging {\n dimension "distribution"\n {...}\n\n system {\n dimension "emoji"\n versionNameSuffix "s"\n }\n compat {\n dimension "emoji"\n }\n }\n\n buildTypes {\n release {\n shrinkResources true\n minifyEnabled true\n proguardFiles getDefaultProguardFile(\'proguard-android.txt\'), \'proguard-rules.pro\'\n //versionNameSuffix "r"\n signingConfig signingConfigs.company\n zipAlignEnabled true\n\n\n }\n debug {\n\n applicationIdSuffix ".dev"\n shrinkResources false\n minifyEnabled false\n proguardFiles getDefaultProguardFile(\'proguard-android.txt\'), \'proguard-rules.pro\'\n\n }\n }\n\n lintOptions {\n checkReleaseBuilds false\n disable \'MissingTranslation\', \'InvalidPackage\', \'MissingQuantity\', \'AppCompatResource\'\n }\n\n subprojects {\n\n afterEvaluate {\n if (getPlugins().hasPlugin(\'android\') ||\n getPlugins().hasPlugin(\'android-library\')) {\n\n configure(android.lintOptions) {\n disable \'AndroidGradlePluginVersion\', \'MissingTranslation\'\n }\n }\n\n }\n }\n\n packagingOptions {\n exclude \'META-INF/BCKEY.DSA\'\n exclude \'META-INF/BCKEY.SF\'\n }\n\n // https://proandroiddev.com/how-to-setup-your-android-app-to-use-protobuf-96132340de5c\n // Added to fix duplicate classes issue\n protobuf {\n protoc {\n // You still need protoc like in the non-Android case\n artifact = \'com.google.protobuf:protoc:3.0.0\'\n }\n plugins {\n javalite {\n // The codegen for lite comes as a separate artifact\n artifact = \'com.google.protobuf:protoc-gen-javalite:3.0.0\'\n }\n }\n generateProtoTasks {\n all().each { task ->\n task.builtins {\n // In most cases you don\'t need the full Java output\n // if you use the lite output.\n remove java\n }\n task.plugins {\n javalite { }\n }\n }\n }\n }\n\n sourceSets{\n main.java.srcDirs += "${protobuf.generatedFilesBaseDir}/main/javalite"\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n为了修复错误,我按照此处和此处的解决方案进行操作,我继续在 protobuf 中收到以下错误。
\n\nDuplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1) \nDuplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)\nDuplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1) \nDuplicate class com.google.protobuf.AbstractParser found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar) com.google.protobuf:protobuf-lite:3.0.1)\nDuplicate class com.google.protobuf.ByteString found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)\nDuplicate class com.google.protobuf.ByteString$1 found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)\nDuplicate class com.google.protobuf.ByteString$ByteIterator found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1) \nDuplicate class com.google.protobuf.ByteString$CodedBuilder found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)\nDuplicate class com.google.protobuf.ByteString$Output found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)\nDuplicate class com.google.protobuf.CodedInputStream found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)\nDuplicate class com.google.protobuf.CodedOutputStream found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)\nDuplicate class com.google.protobuf.CodedOutputStream$OutOfSpaceException found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1) ...\nGo to the documentation to learn how to Fix dependency resolution errors.\nRun Code Online (Sandbox Code Playgroud)\n
作为修复,使用gradle dependencies命令生成 gradle 依赖关系树,此树将显示您从哪里获取protobuf-lite-3.0.1.jar,然后使用 gradle 中的排除模式简单地排除此 jar,如下所示 -
dependencies {
compile('com.example.m:m:1.0') {
exclude group: 'org.unwanted', module: 'x
}
}
Run Code Online (Sandbox Code Playgroud)