Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protobuf duplicate class issue #107

Open
GieMik8 opened this issue May 11, 2020 · 7 comments
Open

Protobuf duplicate class issue #107

GieMik8 opened this issue May 11, 2020 · 7 comments
Labels
prestandard This issue is referring to the "prestandard" solution and not the current GAEN implementation.

Comments

@GieMik8
Copy link

GieMik8 commented May 11, 2020

Hello, I am trying to implement your library into our project and getting some troubles.

Protobuf issue:

> 1 exception was raised by workers:
  java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractParser found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractProtobufList found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.Any found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.Any$1 found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.Any$Builder found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.AnyOrBuilder found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.AnyProto found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.Api found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.Api$1 found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)

...of course, error code continues much further.

Have tried to look for a workaround, but nothing works out perfectly.

Have tried to exclude sub dependency:

    implementation ('org.dpppt:dp3t-sdk-android:0.2.6') {
        exclude group: "com.google.protobuf", module: "protobuf-javalite"
    }

And at least it helps to build the project. However, when invoking initialize method error happens:
96377800_2888651507855850_8247697695045582848_n

We are using firebase config and firebase inappmessaging in our project.

Is there any way to make it work?

Any help appreciated.

@jeffallen
Copy link
Contributor

I was not able to repro this.

I made a new Hello World project, targeting API level 23 (see #16 for why).

I added this to my app/build.gradle:

    def dp3t_sdk_version = '0.2.6'
    implementation "org.dpppt:dp3t-sdk-android:$dp3t_sdk_version"

I went to the layout editor and gave the Hello World text box the id hello. I added this to my MainActivity.kt:

        setContentView(R.layout.activity_main)
        hello.text = org.dpppt.android.sdk.BuildConfig.VERSION_NAME;

I got the error mentioned in this SO posting: https://stackoverflow.com/questions/49891730/invoke-customs-are-only-supported-starting-with-android-0-min-api-26

I fixed it by adding this in app/build.gradle:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

I was then able to get a minimal app running that linked against the DP-3T JAR file. (I was also able to call DP3T.init() as well, though you'll need to figure out how to get the PublicKey that it needs. See the calibration app.)

@eltonhealy7
Copy link

Hello, I am trying to implement your library into our project and getting some troubles.

Protobuf issue:

> 1 exception was raised by workers:
  java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractParser found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractProtobufList found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.Any found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.Any$1 found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.Any$Builder found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.AnyOrBuilder found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.AnyProto found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.Api found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
  Duplicate class com.google.protobuf.Api$1 found in modules protobuf-javalite-3.11.4.jar (com.google.protobuf:protobuf-javalite:3.11.4) and protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)

...of course, error code continues much further.

Have tried to look for a workaround, but nothing works out perfectly.

Have tried to exclude sub dependency:

    implementation ('org.dpppt:dp3t-sdk-android:0.2.6') {
        exclude group: "com.google.protobuf", module: "protobuf-javalite"
    }

And at least it helps to build the project. However, when invoking initialize method error happens:
96377800_2888651507855850_8247697695045582848_n

We are using firebase config and firebase inappmessaging in our project.

Is there any way to make it work?

Any help appreciated.

@GieMik8
Copy link
Author

GieMik8 commented May 16, 2020

@jeffallen

I have managed to reproduce the issue in demo calibration app project.

Building the project starts to fail when adding implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.6' in app dependencies.

build.gradle project:

/*
 * Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * SPDX-License-Identifier: MPL-2.0
 */

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.12'
        classpath 'com.google.gms:google-services:4.2.0' // here
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle app:

/*
 * Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * SPDX-License-Identifier: MPL-2.0
 */

apply plugin: 'com.android.application'

ext.readProperty = { paramName ->
	if (project.hasProperty(paramName)) {
		return project.getProperties().get(paramName)
	} else {
		Properties properties = new Properties()
		if (project.rootProject.file('local.properties').exists()) {
			properties.load(project.rootProject.file('local.properties').newDataInputStream())
		}
		return properties.getProperty(paramName)
	}
}

android {
	compileSdkVersion 29
	buildToolsVersion "29.0.3"

	defaultConfig {
		applicationId "org.dpppt.android.calibration"
		minSdkVersion 23
		targetSdkVersion 29
		versionCode 1
		versionName "0.1"

		missingDimensionStrategy 'version', 'calibration'

		testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
	}

	signingConfigs {
		release {
			storeFile file('../testKeystore')
			storePassword readProperty('keystorePassword')
			keyAlias 'keyAlias'
			keyPassword readProperty('keyAliasPassword')
		}
	}
	buildTypes {
		release {
			signingConfig signingConfigs.release
		}
	}

	compileOptions {
		sourceCompatibility JavaVersion.VERSION_1_8
		targetCompatibility JavaVersion.VERSION_1_8
	}

	buildTypes {
		release {
			minifyEnabled true
			proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
		}
	}

}

dependencies {
	implementation fileTree(dir: 'libs', include: ['*.jar'])

	implementation project(':dp3t-sdk')

	implementation 'androidx.appcompat:appcompat:1.1.0'
	implementation 'androidx.core:core:1.2.0'
	implementation 'androidx.fragment:fragment:1.2.4'
	implementation 'androidx.work:work-runtime:2.3.4'

	implementation 'com.squareup.retrofit2:retrofit:2.8.1'
	implementation 'com.squareup.retrofit2:converter-gson:2.8.1'

	implementation 'com.google.android.material:material:1.1.0'
	implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.6' // here
}

apply plugin: 'com.google.gms.google-services' // here

Also, in order to reproduce it you will need google-services.json file (https://support.google.com/firebase/answer/7015592?hl=en).

@jeffallen
Copy link
Contributor

Not pointing fingers here, but how is it a DP-3T problem that when you add firebase to your app, it starts to fail?

@GieMik8
Copy link
Author

GieMik8 commented May 16, 2020

Not pointing fingers here, but how is it a DP-3T problem that when you add firebase to your app, it starts to fail?

Good point @jeffallen but in my case I have included DP-3T into our project later (we are using Firebase for quite some time). It would be great to use both libraries in our project. Firebase is important for most apps.

@simonroesch simonroesch added the prestandard This issue is referring to the "prestandard" solution and not the current GAEN implementation. label May 19, 2020
@dev-wanjihia
Copy link

@jeffallen

I have managed to reproduce the issue in demo calibration app project.

Building the project starts to fail when adding implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.6' in app dependencies.

build.gradle project:

/*
 * Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * SPDX-License-Identifier: MPL-2.0
 */

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.12'
        classpath 'com.google.gms:google-services:4.2.0' // here
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle app:

/*
 * Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * SPDX-License-Identifier: MPL-2.0
 */

apply plugin: 'com.android.application'

ext.readProperty = { paramName ->
	if (project.hasProperty(paramName)) {
		return project.getProperties().get(paramName)
	} else {
		Properties properties = new Properties()
		if (project.rootProject.file('local.properties').exists()) {
			properties.load(project.rootProject.file('local.properties').newDataInputStream())
		}
		return properties.getProperty(paramName)
	}
}

android {
	compileSdkVersion 29
	buildToolsVersion "29.0.3"

	defaultConfig {
		applicationId "org.dpppt.android.calibration"
		minSdkVersion 23
		targetSdkVersion 29
		versionCode 1
		versionName "0.1"

		missingDimensionStrategy 'version', 'calibration'

		testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
	}

	signingConfigs {
		release {
			storeFile file('../testKeystore')
			storePassword readProperty('keystorePassword')
			keyAlias 'keyAlias'
			keyPassword readProperty('keyAliasPassword')
		}
	}
	buildTypes {
		release {
			signingConfig signingConfigs.release
		}
	}

	compileOptions {
		sourceCompatibility JavaVersion.VERSION_1_8
		targetCompatibility JavaVersion.VERSION_1_8
	}

	buildTypes {
		release {
			minifyEnabled true
			proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
		}
	}

}

dependencies {
	implementation fileTree(dir: 'libs', include: ['*.jar'])

	implementation project(':dp3t-sdk')

	implementation 'androidx.appcompat:appcompat:1.1.0'
	implementation 'androidx.core:core:1.2.0'
	implementation 'androidx.fragment:fragment:1.2.4'
	implementation 'androidx.work:work-runtime:2.3.4'

	implementation 'com.squareup.retrofit2:retrofit:2.8.1'
	implementation 'com.squareup.retrofit2:converter-gson:2.8.1'

	implementation 'com.google.android.material:material:1.1.0'
	implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.6' // here
}

apply plugin: 'com.google.gms.google-services' // here

Also, in order to reproduce it you will need google-services.json file (https://support.google.com/firebase/answer/7015592?hl=en).

Exclude the protobuf group when adding the firebase dependency. This worked for me.

implementation ("com.google.firebase:firebase-config:19.2.0",{ exclude group: 'com.google.protobuf' })

@jaafarnejm
Copy link

This error means that you are importing two packages that use Protobuf for your project, one of them has a distribution that's conflicting with the other.

If you encountered this problem on Flutter, you can reconsider the version number of your dependencies in pubspec.yaml, and replace "any" by an exact version number.
For example, under "dependencies:" change:

barcode_scan: any

To:

barcode_scan: ^2.0.0

I hope I helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prestandard This issue is referring to the "prestandard" solution and not the current GAEN implementation.
Projects
None yet
Development

No branches or pull requests

6 participants