[HELP WANTED] How to build Android with Expokit sdk34 ?

First I would like to state that I have built successfully for iOS.
The laconic documentation says : ./gradlew installDebug.
I found no information about the needed environnement for building Android ejected apps, so the build fails with this error

> Task :app:processDebugManifest FAILED
/Users/laurent/Work/fame/v0/fameapp/android/app/src/main/AndroidManifest.xml:22:18-91 Error:
        Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:48:3-367:17 to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:48:3-367:17 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 8m 56s
509 actionable tasks: 479 executed, 30 up-to-date

This “Manifest merger error” was fixed by adding in application

<application
    android:name=".MainApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:usesCleartextTraffic="true"
    tools:replace="android:appComponentFactory"
    android:appComponentFactory="whateverString">

Then next error is :

> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: androidx.versionedparcelable.CustomVersionedParcelable

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: androidx.versionedparcelable.CustomVersionedParcelable

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 49s

this issue let me to this article

Is there someone at @expo or here that was able to build successfully an ejected SDK34 app for Android ? In that case, which versions of tools (android studio, gradle, android sdk tools …) are needed ?

@lc3t35 after a lot of trial and error with updating to 33 and now updating to 34, I found the best combo for gradle is wrapper settings w gradle dist 4.10.2 and build tools 3.3.0 (or 3.3.1, 3.3.2)

make sure you have this in your app build.gradle under dependencies:

  implementation('host.exp.exponent:expoview:34.0.0@aar') {
    transitive = true
    exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    exclude group: 'com.squareup.okhttp3', module: 'okhttp-urlconnection'
  }

  api 'com.facebook.react:react-native:34.0.0'

and you might want to try forcing build tools 28 in the project build.gradle:

subprojects { subproject ->
  afterEvaluate{
    if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
      android {
        compileSdkVersion rootProject.ext.compileSdkVersion
        buildToolsVersion rootProject.ext.buildToolsVersion
      }
    }
  }
}

another thing to try after making the above changes is File -> Invalidate Caches / Restart and/or in the .idea/ dir remove modules.xml file and caches dir, then run gradle sync or restart AS

good times!

Thank you @helium !

So the first tip is : don’t update gradle to 5.x as suggested by Android Studio…
In order to install a previous version of gradle on OSX, as it is not provided by homebrew, I used the excellent sdkman :

% curl -s "https://get.sdkman.io" | bash
% sdk install gradle 4.10.3
% gradle --version
Welcome to Gradle 4.10.3!
Here are the highlights of this release:
 - Incremental Java compilation by default
 - Periodic Gradle caches cleanup
 - Gradle Kotlin DSL 1.0-RC6
 - Nested included builds
 - SNAPSHOT plugin versions in the `plugins {}` block
For more details see https://docs.gradle.org/4.10.3/release-notes.html
------------------------------------------------------------
Gradle 4.10.3
------------------------------------------------------------
Build time:   2018-12-05 00:50:54 UTC
Revision:     e76905e3a1034e6f724566aeb985621347ff43bc

Kotlin DSL:   1.0-rc-6
Kotlin:       1.2.61
Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
OS:           Mac OS X 10.13.6 x86_64

I noticed I have an additional item before com.facebook.react:react-native:34.0.0 :

api 'org.webkit:android-jsc:r245459' // needs to be before react-native
api 'com.facebook.react:react-native:34.0.0'

I removed it and gave it a try with Android Studio 3.4.

The current status of build is :

> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: androidx.versionedparcelable.CustomVersionedParcelable

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: androidx.versionedparcelable.CustomVersionedParcelable

Found the same issue (open) here in react-native-image-picker repo : https://github.com/react-native-community/react-native-image-picker/issues/1119

Downgrading Android Studio to 3.3.2 from https://developer.android.com/studio/archive

Always the same : how can I fix
Program type already present: androidx.versionedparcelable.CustomVersionedParcelable problem ?

% expo diagnostics

Expo CLI 3.0.10 environment info:
    System:
      OS: macOS High Sierra 10.13.6
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.0 - /usr/local/bin/node
      Yarn: 1.17.3 - ~/.yarn/bin/yarn
      npm: 6.11.2 - ~/.npm-global/bin/npm
      Watchman: 4.7.0 - /usr/local/bin/watchman
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmGlobalPackages:
      expo-cli: 3.0.10

gradle.properties

android.useDeprecatedNdk=true
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx9216M -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.configureondemand=true
org.gradle.internal.repository.initial.backoff=1000
android.useAndroidX=false
android.enableJetifier=false

@lc3t35 a few more things to try

  • you don’t need to install gradle, AS will do it for you whenever you modify the wrapper settings dist (you can see all the versions under your /android/.gradle dir)

  • check and make sure you have the latest versions of your RN modules in package.json, you may need to update versions or even downgrade to be compatible w expo 34 (run expo install ... to install correct versions)

  • delete node_modules and android/.gradle dir, then do yarn install then gradle sync or restart of AS

  • fwiw I do not have

android.useAndroidX=false
android.enableJetifier=false

in my wrapper.properties file

  • make sure your app gradle android prop has sdk vers 28 and build tools 28.0.3 and also force sub-projects to use those (as I mentioned in first reply)

One thing I should add here that I’ve noticed caused some problems for others ->

When opening the project, Android Studio may prompt you to upgrade the version of Gradle or other build tools, but don’t do this as you may get unexpected results. ExpoKit always ships with the latest supported versions of all build tools. (from our docs)

After being able to build a debug apk, here is the new episode when I try to build and generate a signed bundled release : [SDK34, Ejected, Android] Duplicate jar entry [com/facebook/react/uimanager/UIManagerReanimatedHelper.class]