GithubHelp home page GithubHelp logo

Gradle error when building about flipper HOT 29 CLOSED

facebook avatar facebook commented on April 26, 2024 34
Gradle error when building

from flipper.

Comments (29)

friederbluemle avatar friederbluemle commented on April 26, 2024 16

There is definitely a packaging problem with version 0.0.1 of the library. It includes all class files of the dependencies (including the support library, Guava files, OkHttp, ...):

The exclude group statements for debugImplementation suggested above won't work in this case. They only work for dependencies that are declared in the pom file (sonar-0.0.1 does not declare any dependencies there - they are all bundled inside of the aar).

The only way I could get it to work is to manually extract the aar file (and the contained classes.jar file), repackage them, then directly reference them in my build.gradle file.

It went something like this:

mkdir -p ~/tmp/sonar-0.0.1
cp ~/.gradle/caches/modules-2/files-2.1/com.facebook.sonar/de84b64d6ab7a9b71e80875f5fb6cabf040eb06/sonar-0.0.1.aar ~/tmp/sonar-0.0.1/
cd ~/tmp/sonar-0.0.1
unzip sonar-0.0.1.aar -d aar-0.0.1
cp aar-0.0.1/classes.jar .
unzip classes.jar -d classes-0.0.1

# Now delete all the unwanted packaged class files, e.g.
rm -rf classes-0.0.1/android classes-0.0.1/javax classes-0.0.1/jsr-305

# Repackage classes file
jar cvf classes.jar -C classes-0.0.1/ .

# Repackage aar file
cp classes.jar aar-0.0.1/
jar cvf sonar-0.0.1-LOCAL.aar -C aar-0.0.1/ .

# Now use the new aar file directly:

cp sonar-0.0.1-LOCAL.aar ~/path/to/android-project/app/libs

# build.gradle

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

# app/build.gradle

dependencies {
    // ...
    debugImplementation(name: 'sonar-0.0.1-LOCAL', ext: 'aar')
}

from flipper.

kypeli avatar kypeli commented on April 26, 2024 12

I have a hard time understanding how the Sonar library in its current form would work with any external real application out there. I am facing similar issue but with OkHttp3

Program type already present: okhttp3.Authenticator$1
Message{kind=ERROR, text=Program type already present: okhttp3.Authenticator$1, sources=[Unknown source file], tool name=Optional.of(D8)}

And since OkHttp3 is pretty common [sarcasm], how on earth can Sonar in its current form work in real production apps? So this library has to be slimmed down and not ship with all these baked in dependencies.

from flipper.

TurKorsaN avatar TurKorsaN commented on April 26, 2024 10

looks like sonar has all dependencies packaged inside of it. try to implement like this

debugImplementation ('com.facebook.sonar:sonar:0.0.1'){
exclude group: 'android'
exclude group: 'javax'
exclude group: 'jsr-305'
exclude group: 'okhttp3'
exclude group: 'okio'
exclude group: 'org'
exclude group: 'com.google'
}

from flipper.

rigor789 avatar rigor789 commented on April 26, 2024 3

I tried to use the following snippet (I can't remember where it was from, I used it in a past project)

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == "com.android.support") {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "27.+"
            }
        }
    }
}

But that din't seem to solve the issue.

from flipper.

KeithYokoma avatar KeithYokoma commented on April 26, 2024 2

I've got the similar error in the Android Issues section:

Program type already present: okio.Util
Message{kind=ERROR, text=Program type already present: okio.Util, sources=[Unknown source file], tool name=Optional.of(D8)}

from flipper.

passy avatar passy commented on April 26, 2024 2

@sgrekov You can get them from by adding https://oss.sonatype.org/content/repositories/snapshots/ as repository. But thanks for pointing that out; that should not be necessary.

I'll bump the Litho dependencies back to stable and push out another release with them included.

from flipper.

Swordsman-Inaction avatar Swordsman-Inaction commented on April 26, 2024 2

@passy Hi, got an error, found both libs have libsonarfb.so after unpack the aar.

Execution failed for task ':mobile:transformNativeLibsWithMergeJniLibsForDebug'.
> More than one file was found with OS independent path 'lib/armeabi-v7a/libsonarfb.so'

from flipper.

jiantao88 avatar jiantao88 commented on April 26, 2024 1

Hope that the official can provide AAR file

from flipper.

friederbluemle avatar friederbluemle commented on April 26, 2024 1

@erawhctim Hmm, is it possible that your existing dependencies have some conflict?

Try

./gradlew :app:dependencies

I assume you already completely cleaned the project after modifying the aar file, to remove any chance for cached file problems? You may also try ./gradlew --stop to stop running instances the Gradle wrapper (although unlikely related to that).

from flipper.

priteshrnandgaonkar avatar priteshrnandgaonkar commented on April 26, 2024 1

@Swordsman-Inaction You can add the following

   packagingOptions {
        pickFirst 'lib/armeabi-v7a/libsonarfb.so'
        pickFirst 'lib/x86/libsonarfb.so'
        pickFirst 'lib/x86_64/libsonarfb.so'
        pickFirst 'lib/arm64-v8a/libsonarfb.so'
    }

from flipper.

passy avatar passy commented on April 26, 2024 1

One more try. :) Published 0.0.8 which no longer includes two copies of libsonarfb.so, so you don't have to use pickFirst or other hacks. x86_64 is still not supported, but we're looking into that as part of #111 as we're trying to find a version of OpenSSL that's compatible with folly and compiles with modern NDK versions.

from flipper.

rigor789 avatar rigor789 commented on April 26, 2024

@TurKorsaN I couldn't get it to work, the same error is thrown (even after cleaning and trying to re-build)

from flipper.

talsemgeest avatar talsemgeest commented on April 26, 2024

I have the same issue:
AGPBI: {"kind":"error","text":"Program type already present: androidx.fragment.app.FragmentManager$OnBackStackChangedListener","sources":[{}],"tool":"D8"}

from flipper.

jiangkang avatar jiangkang commented on April 26, 2024

I have the same issue:

  • What went wrong:
    Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:

from flipper.

ebarrenechea avatar ebarrenechea commented on April 26, 2024

@jiangkang This just means you have other conflicting dependencies. The steps above only removed the support library, annotations and a few other things. Your project might have dependencies on OkHttp or Okio, for example. You'll need to remove those as well.

from flipper.

erawhctim avatar erawhctim commented on April 26, 2024

@friederbluemle Thanks for the tip!

I followed your steps and was able to strip out the duplicated javax classes that gradle/D8 was complaining about, but I'm still seeing a similar error - D8: Program type already present: javax.annotation.concurrent.ThreadSafe (even though I've double checked and removed all the javax.* classes before recompiling as a local AAR.

Any ideas?

from flipper.

erawhctim avatar erawhctim commented on April 26, 2024

@friederbluemle Hmm, I think you might be right. Looks like realm-android-library depends on FindBugs' JSR305 so maybe the javax.* classes are coming in from there.

debugCompileClasspath - Resolved configuration for compilation for variant: debug
+--- io.realm:realm-annotations:5.3.0
+--- io.realm:realm-android-library:5.3.0
|    +--- com.google.code.findbugs:jsr305:3.0.2
|    +--- com.getkeepsafe.relinker:relinker:1.2.2
|    \--- io.realm:realm-annotations:5.3.0
+--- io.realm:realm-android-kotlin-extensions:5.3.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.10
|         \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.10
|              \--- org.jetbrains:annotations:13.0
+--- project :sonar-0.0.1-LOCAL
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.10 (*)
\--- org.jetbrains.anko:anko-commons:0.10.4
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.2.10 (*)

I tried excluding that from the realm gradle plugin declaration like this, but that didn't work like I expected it to:

classpath("io.realm:realm-gradle-plugin:5.3.0") {
    exclude group: 'com.google.code.findbugs', module: 'jsr305'
}

from flipper.

Microhx avatar Microhx commented on April 26, 2024

met the same issue again:

:app:transformDexArchiveWithExternalLibsDexMergerForDebug
-- | --

how can I fix ???

from flipper.

passy avatar passy commented on April 26, 2024

@priteshrnandgaonkar and I are still working on a full solution, but we've got a stop-gap that should already help a great deal.

If you include this repository (while we're waiting for JCenter to approve a new package) ...

repositories {
    maven { url 'https://dl.bintray.com/facebook/maven/' }
}

... and depend on ...

debugImplementation 'com.facebook.sonar:sonar:0.0.4

... then you should be able to use Sonar in your Android project. For now we DO NOT support x86_64 due to an OpenSSL compilation issue, but armv7, armv8 and x86 should all work just fine.

from flipper.

passy avatar passy commented on April 26, 2024

Another update on this: The extra repository is no longer necessary as the new dependency got promoted into JCenter proper.

from flipper.

sgrekov avatar sgrekov commented on April 26, 2024

com.facebook.sonar:sonar:0.0.4 depends on
+--- com.facebook.litho:litho-core:0.15.1-SNAPSHOT
| +--- com.facebook.litho:litho-widget:0.15.1-SNAPSHOT

But they are not on jcenter nor on the https://dl.bintray.com/facebook/maven/

from flipper.

passy avatar passy commented on April 26, 2024

Pushed 0.0.5 which no longer depends on Litho snapshots.

from flipper.

Swordsman-Inaction avatar Swordsman-Inaction commented on April 26, 2024

@passy Don't forget to push com.facebook.sonar:fbjni too. 0.0.5 is currently not available but required by the lib.

from flipper.

passy avatar passy commented on April 26, 2024

@Swordsman-Inaction Thanks! The task silently failed to publish the release because the javadoc generation failed with an odd error. Uploading now.

from flipper.

passy avatar passy commented on April 26, 2024

@Swordsman-Inaction The workaround from @priteshrnandgaonkar should work, but it's still something we shouldn't force you to do. I'll try to exclude the library from getting bundled into the sonar AAR. Pulling it in from one place should be enough.

from flipper.

ShaishavGandhi avatar ShaishavGandhi commented on April 26, 2024

Is this issue resolved? I still face it.

from flipper.

kaleai avatar kaleai commented on April 26, 2024
maven { url 'https://dl.bintray.com/facebook/maven/' }
debugImplementation 'com.facebook.sonar:sonar:0.0.9'

@shaishavgandhi05

from flipper.

passy avatar passy commented on April 26, 2024

Yes, the newer versions address this. Closing this here now. :)

from flipper.

IDFDeveloper avatar IDFDeveloper commented on April 26, 2024

I have solved my issue by using this configurations in gradle file. You save my day. Thanks !

from flipper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.