React Native Building In Android and iOS: After Ejecting(Detaching) Expo
I am trying to build React Native app for android and iOS but keep finding one and other issues. After so much struggle I succeeded with initial hickups but now struck at one point where I am not finding any solution.
Problems I am facing with React Native Build For Android and iOS , before encountering the issue I followed the below steps
1. Install Cocoapods (https://cocoapods.org/)
2. Run pod install from your project’s ios directory.
3. Run ‘react-native run-ios’ in the project root folder.
4. Run ‘react-native run-android’ in the project root folder.
After running react-native run-android I am getting below error.
:app:transformClassesWithJarMergingForDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/auth/api/signin/zzc.class * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 25.103 secs Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment: https://facebook.github.io/react-native/docs/android-setup.html
————————————————————————————————————————————————————————————————————————
My app gradle file looks as follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.mycompany.testapp"
minSdkVersion 20
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
manifestPlaceholders = [
'appAuthRedirectScheme': 'com.mycompany.testapp'
]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "8g"
}
}
task exponentPrebuildStep(type: Exec) {
workingDir '../../'
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
commandLine 'cmd', '/c', '.\\.expo-source\\android\\detach-scripts\\prepare-detached-build.bat'
} else {
commandLine './.expo-source/android/detach-scripts/prepare-detached-build.sh'
}
}
preBuild.dependsOn exponentPrebuildStep
repositories{
flatDir{
dirs 'libs'
}
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile project(':react-native-social-share')
compile project(':react-native-maps')
compile project(':react-native-vector-icons')
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.0'
compile 'com.google.android.gms:play-services-auth:10.2.1'
compile('host.exp.exponent:expoview:21.0.0@aar') {
exclude group: 'com.facebook.android', module: 'facebook-android-sdk'
exclude group: 'com.facebook.android', module: 'audience-network-sdk'
exclude group: 'io.nlopez.smartlocation', module: 'library'
transitive = true;
}
compile ('com.facebook.android:facebook-android-sdk:4.+') {
}
compile('com.facebook.android:audience-network-sdk:4.+') {
exclude module: 'play-services-ads'
}
compile('io.nlopez.smartlocation:library:3.2.11') {
transitive = false
}
}
Solution:
The solution is to find the conflicting dependencies using following command inside your app/android folder
$ ./gradlew app:dependencies
Closely observe the dependency hierarchy and check the conflicted dependency for com.google.android.gms. To resolve this you have to exclude it for specific dependency as follows, see the updated build.gradle file
apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion '26.0.1' defaultConfig { applicationId "com.mycompany.testapp" minSdkVersion 19 targetSdkVersion 25 versionCode 1 versionName "1.0" multiDexEnabled true ndk { abiFilters 'armeabi-v7a', 'x86' } manifestPlaceholders = [ 'appAuthRedirectScheme': 'com.mycompany.testapp' ] } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } dexOptions { javaMaxHeapSize "8g" } } task exponentPrebuildStep(type: Exec) { workingDir '../../' if (System.getProperty('os.name').toLowerCase().contains('windows')) { commandLine 'cmd', '/c', '.\\.expo-source\\android\\detach-scripts\\prepare-detached-build.bat' } else { commandLine './.expo-source/android/detach-scripts/prepare-detached-build.sh' } } preBuild.dependsOn exponentPrebuildStep repositories{ flatDir{ dirs 'libs' } mavenLocal() maven { url 'https://maven.fabric.io/public' } } dependencies { compile project(':react-native-vector-icons') compile(project(':react-native-maps')){ exclude group: 'com.google.android.gms' } compile fileTree(dir: "libs", include: ["*.jar"]) compile 'com.android.support:appcompat-v7:25.3.1' compile "com.facebook.react:react-native:+" // From node_modules compile ("com.google.android.gms:play-services-base:10.0.1") { force = true; } compile ("com.google.android.gms:play-services-maps:10.0.1") { force = true; } compile ("com.google.android.gms:play-services-gcm:10.0.1") { force = true; } compile ('com.google.firebase:firebase-core:10.0.1') { force = true; } testCompile 'junit:junit:4.12' compile project(':react-native-vector-icons') compile(project(':react-native-social-share')){ exclude group: 'com.google.android.gms' } compile('host.exp.exponent:expoview:21.0.0@aar') { exclude group: 'com.facebook.android', module: 'audience-network-sdk' exclude group: 'io.nlopez.smartlocation', module: 'library' exclude group: 'com.google.android.gms' transitive = true; } compile('com.facebook.android:audience-network-sdk:4.+') { exclude module: 'play-services-ads' } compile('io.nlopez.smartlocation:library:3.2.11') { transitive = false } }