Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Conflict with React Native in v2.0.2 #199

Open
LinusU opened this issue Sep 4, 2018 · 6 comments
Open

Conflict with React Native in v2.0.2 #199

LinusU opened this issue Sep 4, 2018 · 6 comments

Comments

@LinusU
Copy link

LinusU commented Sep 4, 2018

Similar to #102 and #196, there is a conflict in the 2.0.2 version as well:

Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/facebook/jni/Countable;
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/facebook/jni/Countable;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:506)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:336)
        at com.android.dx.command.dexer.Main.runDx(Main.java:291)
        at com.android.dx.command.dexer.Main.main(Main.java:247)
        at com.android.dx.command.Main.main(Main.java:94)

Seems like both conceal and react-native is defining com.facebook.jni.Countable.

Would be happy to submit a pull request if someone can guide me to what the proper fix is ☺️

@LinusU
Copy link
Author

LinusU commented Sep 4, 2018

Currently using a very annoying workaround where I strip the duplicated classes from the aar file, and then include it as a local dependency:

# Download original
curl http://central.maven.org/maven2/com/facebook/conceal/conceal/2.0.2/conceal-2.0.2.aar > conceal-2.0.2.aar

# Unpack aar
unzip conceal-2.0.2.aar -d temp-folder

# Strip duplicate so files
rm jni/*/libfb.so

# Unpack classes
cd temp-folder
unzip classes.jar -d temp-folder

# Strip duplicate classes
rm -r temp-folder/com/facebook/{jni,proguard,soloader}

# Pack classes
jar cvf classes.jar -C temp-folder/ .
rm -r temp-folder

# Pack aar
cd ..
jar cvf conceal-2.0.2-stripped.aar -C temp-folder/ .
rm -r temp-folder

@OleksandrKucherenko
Copy link

OleksandrKucherenko commented Oct 18, 2019

configurations {
  repack { transitive = false }
}

ext.concealVersion = "2.0.2"

dependencies {
  /* https://github.com/facebook/conceal/releases */
  repack "com.facebook.conceal:conceal:${concealVersion}"
}

task repackConcealv2(dependsOn: configurations.repack) {
  def generation = "${project.buildDir}/intermediates/repack"
  def conceal = "com.facebook.conceal@${concealVersion}"
  def destination = "${generation}/${conceal}"

  doLast {
    copy {
      from { zipTree(configurations.repack.singleFile) }
      into "${destination}"
    }

    copy {
      from zipTree("${destination}/classes.jar")
      into "${destination}/classes"
    }
  }

  task recreateConcealAarv2(type: Zip) {
    archiveFileName = "com.facebook.conceal-${concealVersion}-patched.aar"
    destinationDirectory = file("${generation}")
    from("${destination}") {
      exclude '**/jni/*/libfb.so'
      exclude '**/classes'
      exclude 'classes.jar'
      rename('classes-patched.jar', 'classes.jar')
    }
  }

  task recreateConcealClassesJarv2(type: Zip) {
    archiveFileName = "classes-patched.jar"
    destinationDirectory = file("${destination}")
    from("${destination}/classes") {
      exclude '**/facebook/jni/'
      exclude '**/facebook/proguard/'
      exclude '**/facebook/soloader/'
    }

    finalizedBy recreateConcealAarv2
  }

  finalizedBy recreateConcealClassesJarv2
}

preBuild.dependsOn(repackConcealv2)

dependencies {
  implementation fileTree(dir: "${project.buildDir}/intermediates/repack", include: ["*-patched.aar"])
}

Outputs:

.
├── com.facebook.conceal-2.0.2-patched.aar
└── [email protected]
    ├── AndroidManifest.xml
    ├── aidl
    ├── assets
    ├── classes
    │   └── com
    │       └── facebook
    │           ├── android
    │           │   └── crypto
    │           │       └── keychain
    │           │           ├── AndroidConceal.class
    │           │           ├── AndroidCryptoLibrary.class
    │           │           ├── SecureRandomFix$LinuxPRNGSecureRandom.class
    │           │           ├── SecureRandomFix$LinuxPRNGSecureRandomProvider.class
    │           │           ├── SecureRandomFix$LocalSecureRandom.class
    │           │           ├── SecureRandomFix.class
    │           │           └── SharedPrefsBackedKeyChain.class
    │           ├── cipher
    │           │   ├── Cipher$DecryptStream.class
    │           │   ├── Cipher$EncryptStream.class
    │           │   ├── Cipher.class
    │           │   ├── IntegrityException.class
    │           │   ├── Mac$DecryptStream.class
    │           │   ├── Mac$EncryptStream.class
    │           │   ├── Mac.class
    │           │   └── jni
    │           │       ├── CipherHybrid.class
    │           │       ├── DecryptHybrid.class
    │           │       ├── EncryptHybrid.class
    │           │       ├── MacDecoderHybrid.class
    │           │       ├── MacEncoderHybrid.class
    │           │       └── PBKDF2Hybrid.class
    │           ├── crypto
    │           │   ├── BuildConfig.class
    │           │   ├── CheckedKeyChain.class
    │           │   ├── Conceal.class
    │           │   ├── Crypto.class
    │           │   ├── CryptoConfig.class
    │           │   ├── Entity.class
    │           │   ├── MacConfig.class
    │           │   ├── VersionCodes.class
    │           │   ├── exception
    │           │   │   ├── CryptoInitializationException.class
    │           │   │   └── KeyChainException.class
    │           │   ├── keychain
    │           │   │   └── KeyChain.class
    │           │   ├── keygen
    │           │   │   └── PasswordBasedKeyDerivation.class
    │           │   ├── proguard
    │           │   │   └── annotations
    │           │   │       ├── DoNotStrip.class
    │           │   │       ├── InternalBuildOnly.class
    │           │   │       └── KeepGettersAndSetters.class
    │           │   ├── streams
    │           │   │   ├── BetterCipherInputStream.class
    │           │   │   └── TailInputStream.class
    │           │   └── util
    │           │       ├── Assertions.class
    │           │       ├── NativeCryptoLibrary.class
    │           │       └── SystemNativeCryptoLibrary.class
    │           ├── jni
    │           │   ├── Countable.class
    │           │   ├── CpuCapabilitiesJni.class
    │           │   ├── DestructorThread$1.class
    │           │   ├── DestructorThread$Destructor.class
    │           │   ├── DestructorThread$DestructorList.class
    │           │   ├── DestructorThread$DestructorStack.class
    │           │   ├── DestructorThread$Terminus.class
    │           │   ├── DestructorThread.class
    │           │   ├── HybridClassBase.class
    │           │   ├── HybridData$Destructor.class
    │           │   ├── HybridData.class
    │           │   ├── IteratorHelper.class
    │           │   ├── JniTerminateHandler.class
    │           │   ├── MapIteratorHelper.class
    │           │   ├── NativeRunnable.class
    │           │   └── ThreadScopeSupport.class
    │           ├── proguard
    │           │   └── annotations
    │           │       ├── DoNotStrip.class
    │           │       └── KeepGettersAndSetters.class
    │           └── soloader
    │               ├── Api18TraceUtils.class
    │               ├── ApkSoSource$ApkUnpacker.class
    │               ├── ApkSoSource.class
    │               ├── DirectorySoSource.class
    │               ├── DoNotOptimize.class
    │               ├── Elf32_Dyn.class
    │               ├── Elf32_Ehdr.class
    │               ├── Elf32_Phdr.class
    │               ├── Elf32_Shdr.class
    │               ├── Elf64_Dyn.class
    │               ├── Elf64_Ehdr.class
    │               ├── Elf64_Phdr.class
    │               ├── Elf64_Shdr.class
    │               ├── ExoSoSource$1.class
    │               ├── ExoSoSource$ExoUnpacker$FileBackedInputDsoIterator.class
    │               ├── ExoSoSource$ExoUnpacker.class
    │               ├── ExoSoSource$FileDso.class
    │               ├── ExoSoSource.class
    │               ├── ExtractFromZipSoSource$1.class
    │               ├── ExtractFromZipSoSource$ZipDso.class
    │               ├── ExtractFromZipSoSource$ZipUnpacker$ZipBackedInputDsoIterator.class
    │               ├── ExtractFromZipSoSource$ZipUnpacker.class
    │               ├── ExtractFromZipSoSource.class
    │               ├── FileLocker.class
    │               ├── MergedSoMapping.class
    │               ├── MinElf$ElfError.class
    │               ├── MinElf.class
    │               ├── NativeLibrary.class
    │               ├── NoopSoSource.class
    │               ├── SoFileLoader.class
    │               ├── SoLoader$1.class
    │               ├── SoLoader$Api14Utils.class
    │               ├── SoLoader$WrongAbiError.class
    │               ├── SoLoader.class
    │               ├── SoSource.class
    │               ├── SysUtil$LollipopSysdeps.class
    │               ├── SysUtil.class
    │               ├── SystemLoadLibraryWrapper.class
    │               ├── UnpackingSoSource$1.class
    │               ├── UnpackingSoSource$Dso.class
    │               ├── UnpackingSoSource$DsoManifest.class
    │               ├── UnpackingSoSource$InputDso.class
    │               ├── UnpackingSoSource$InputDsoIterator.class
    │               ├── UnpackingSoSource$Unpacker.class
    │               └── UnpackingSoSource.class
    ├── classes-patched.jar
    ├── classes.jar
    ├── jni
    │   ├── arm64-v8a
    │   │   ├── libconcealjni.so
    │   │   └── libfb.so
    │   ├── armeabi
    │   │   ├── libconcealjni.so
    │   │   └── libfb.so
    │   ├── armeabi-v7a
    │   │   ├── libconcealjni.so
    │   │   └── libfb.so
    │   ├── x86
    │   │   ├── libconcealjni.so
    │   │   └── libfb.so
    │   └── x86_64
    │       ├── libconcealjni.so
    │       └── libfb.so
    ├── libs
    └── res

@Kranthi94
Copy link

Any Update on this..?

@Kranthi94
Copy link

@OleksandrKucherenko , I followed your approach but after that native library loading is failing.
Throwing "libconcealjni.so" file is not found. Did you face any such issue..?

@OleksandrKucherenko
Copy link

Throwing "libconcealjni.so" file is not found. Did you face any such issue..?

Yes, I saw that before... it happens due to the not properly found @aar file.

The workaround is to divide the build process into two steps:

  • repack and compose a patched aar
  • copy patched aar into project folder and include it directly (issue is in gradle android plugin that cannot recognize aar archive, it only understands well JARs)

@Kranthi94
Copy link

We had patched the aar according to @LinusU. But still facing the error. By the way, we are using conceal 2.0.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants