[SOLVED] Post Facebook integration issue : cocos compile failed

Hi Everyone,

After integrating facebook, my build.gradle looks like this.

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
        versionCode 1
        versionName "1.0"
        minSdkVersion 15
        targetSdkVersion 22

    }
    sourceSets.main {
        aidl.srcDir "../java/src"
        java.srcDir "../java/src"
        manifest.srcFile "AndroidManifest.xml"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies { 
    compile fileTree( include: ['*.jar'], dir: '../java/libs')
    compile project(':facebook_lib')
}

When I do cocos compile, I am getting the below exception.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':BreakPots:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/util/LongSparseArray.class

Pleas help me to fix this issue. Struggling for more than two days.

which version of cocos2d-x are you using?

Can you double check your project and see if you have duplicate android-support-v4.jar?

No. I have found the reason for this issue and I have fixed it.

Reason: We have separate build.gradle files for our app module and libcocos2dx module.

Android compileSDK version and Target version is 23 in app module’s build.gradle file and it is 22 in libcocos2dx module’s build.gradle file.

Changed it to 22 in both. worked like charm.

Later increased to 23 on both and have got another issue with “org.apache.” in gradle build. Fixed it by adding

 useLibrary 'org.apache.http.legacy'

to build.gradle of app module.

Thank you so much for the response @nite!

Thanks for posting the answer :slight_smile:

1 Like

I tried with this solution,still i can’t able to resolve this issue.
After changing minSdkVersion from 22 to 19,i got this issue.Please help me to fix this issue.

Can you do pastebin your build.gradle files of both modules libcocos2dx and app?

Here is my app bulid.gradle file looks like this

  apply plugin: 'com.android.application'
    android {
        compileSdkVersion 23
        buildToolsVersion '23.0.3
    
        defaultConfig {
            applicationId "com.cube26.EverestClimb"
            minSdkVersion 19
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
    
        }
        sourceSets.main {
            java.srcDir "src"
            res.srcDir "res"
            jniLibs.srcDir "libs"
            manifest.srcFile "AndroidManifest.xml"
            assets.srcDir "assets"
        }
        signingConfigs {
    
            release {
                if (project.hasProperty("RELEASE_STORE_FILE")) {
                    storeFile file(RELEASE_STORE_FILE)
                    storePassword RELEASE_STORE_PASSWORD
                    keyAlias RELEASE_KEY_ALIAS
                    keyPassword RELEASE_KEY_PASSWORD
                }
            }
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                if (project.hasProperty("RELEASE_STORE_FILE")) {
                    signingConfig signingConfigs.release
                }
            }
        }
        productFlavors {
        }
    
    }
    dependencies {
        compile 'com.android.support:multidex:1.0.1'
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile project(':libcocos2dx')
    
        compile 'com.google.android.gms:play-services-analytics:9.0.2'
        compile('com.android.support:appcompat-v7:23.2.1') {
            exclude module: 'support-v4'
            exclude module: 'support-annotations'
        }
        compile('com.android.support:design:23.2.1') {
            exclude module: 'support-v4'
            exclude module: 'support-annotations'
        }
        // 8.4 is the latest as of now, keep it updated
        compile 'com.google.android.gms:play-services:9.0.2'
        compile project(':BaseGameUtils')
    
        compile project(':paymentlibrary-release')
    }

libcocos2dx build.gradle file looks like this

apply plugin: 'com.android.library'

android {

    compileSdkVersion 23
    buildToolsVersion '23.0.3'
    useLibrary  'org.apache.http.legacy'
    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    sourceSets.main {
        aidl.srcDir "../java/src"
        java.srcDir "../java/src"
        manifest.srcFile "AndroidManifest.xml"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: '../java/libs', include: ['*.jar'])
}

Not able to pin point.
Please revisit your dependencies section, java/libs folder and libs folder in libcocos2dx.
Please run gradle task “androiddependency”. You will get know more details to resolve this issue.

Hope you solve!

Thanks for your reply.

Just remove all your files in build folder and try compiling it again!

I tried by removing all files in build folder and compiled then, i am getting error as like this.

  com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: 
    java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

Can you please help me to fix this error.

can you show us the output of this command ?

Hi @nite

This is the output.

Information:Gradle tasks [androidDependencies]
:BreakPots:androidDependencies
debug
— proj.android-studio:libcocos2dx:unspecified
±-- LOCAL: android-async-http-1.4.8.jar
±-- LOCAL: OneSignalSDK.jar
±-- LOCAL: PluginAdMob.jar
±-- LOCAL: PluginFacebook.jar
±-- LOCAL: PluginOneSignal.jar
±-- LOCAL: PluginReview.jar
±-- LOCAL: PluginSdkboxAds.jar
±-- LOCAL: PluginSdkboxPlay.jar
±-- LOCAL: sdkbox.jar
±-- com.facebook.android:facebook_lib:4.6.0
| ±-- LOCAL: android-support-v4.jar
| — LOCAL: bolts-android-1.1.2.jar
— proj.android-studio:gps:unspecified
— LOCAL: google-play-services.jar
debugAndroidTest
No dependencies
debugUnitTest
No dependencies
release
— proj.android-studio:libcocos2dx:unspecified
±-- LOCAL: android-async-http-1.4.8.jar
±-- LOCAL: OneSignalSDK.jar
±-- LOCAL: PluginAdMob.jar
±-- LOCAL: PluginFacebook.jar
±-- LOCAL: PluginOneSignal.jar
±-- LOCAL: PluginReview.jar
±-- LOCAL: PluginSdkboxAds.jar
±-- LOCAL: PluginSdkboxPlay.jar
±-- LOCAL: sdkbox.jar
±-- com.facebook.android:facebook_lib:4.6.0
| ±-- LOCAL: android-support-v4.jar
| — LOCAL: bolts-android-1.1.2.jar
— proj.android-studio:gps:unspecified
— LOCAL: google-play-services.jar
releaseUnitTest
No dependencies
:facebook_lib:androidDependencies
debug
±-- LOCAL: android-support-v4.jar
— LOCAL: bolts-android-1.1.2.jar
debugAndroidTest
±-- LOCAL: android-support-v4.jar
±-- LOCAL: bolts-android-1.1.2.jar
— debug
±-- LOCAL: android-support-v4.jar
— LOCAL: bolts-android-1.1.2.jar
debugUnitTest
±-- LOCAL: android-support-v4.jar
±-- LOCAL: bolts-android-1.1.2.jar
— debug
±-- LOCAL: android-support-v4.jar
— LOCAL: bolts-android-1.1.2.jar
release
±-- LOCAL: android-support-v4.jar
— LOCAL: bolts-android-1.1.2.jar
releaseUnitTest
±-- LOCAL: android-support-v4.jar
±-- LOCAL: bolts-android-1.1.2.jar
— release
±-- LOCAL: android-support-v4.jar
— LOCAL: bolts-android-1.1.2.jar
:gps:androidDependencies
debug
— LOCAL: google-play-services.jar
debugAndroidTest
±-- LOCAL: google-play-services.jar
— debug
— LOCAL: google-play-services.jar
debugUnitTest
±-- LOCAL: google-play-services.jar
— debug
— LOCAL: google-play-services.jar
release
— LOCAL: google-play-services.jar
releaseUnitTest
±-- LOCAL: google-play-services.jar
— release
— LOCAL: google-play-services.jar
:libcocos2dx:androidDependencies
debug
±-- LOCAL: PluginFacebook.jar
±-- LOCAL: OneSignalSDK.jar
±-- LOCAL: PluginReview.jar
±-- LOCAL: PluginOneSignal.jar
±-- LOCAL: PluginSdkboxAds.jar
±-- LOCAL: sdkbox.jar
±-- LOCAL: PluginAdMob.jar
±-- LOCAL: PluginSdkboxPlay.jar
±-- LOCAL: android-async-http-1.4.8.jar
±-- com.facebook.android:facebook_lib:4.6.0
| ±-- LOCAL: android-support-v4.jar
| — LOCAL: bolts-android-1.1.2.jar
— proj.android-studio:gps:unspecified
— LOCAL: google-play-services.jar
debugAndroidTest
±-- LOCAL: PluginFacebook.jar
±-- LOCAL: OneSignalSDK.jar
±-- LOCAL: PluginReview.jar
±-- LOCAL: PluginOneSignal.jar
±-- LOCAL: PluginSdkboxAds.jar
±-- LOCAL: sdkbox.jar
±-- LOCAL: PluginAdMob.jar
±-- LOCAL: PluginSdkboxPlay.jar
±-- LOCAL: android-async-http-1.4.8.jar
±-- debug
| ±-- LOCAL: android-async-http-1.4.8.jar
| ±-- LOCAL: OneSignalSDK.jar
| ±-- LOCAL: PluginAdMob.jar
| ±-- LOCAL: PluginFacebook.jar
| ±-- LOCAL: PluginOneSignal.jar
| ±-- LOCAL: PluginReview.jar
| ±-- LOCAL: PluginSdkboxAds.jar
| ±-- LOCAL: PluginSdkboxPlay.jar
| ±-- LOCAL: sdkbox.jar
| ±-- com.facebook.android:facebook_lib:4.6.0
Error:±-- LOCAL: android-support-v4.jar
Error:— LOCAL: bolts-android-1.1.2.jar
| — proj.android-studio:gps:unspecified
| — LOCAL: google-play-services.jar
±-- com.facebook.android:facebook_lib:4.6.0
| ±-- LOCAL: android-support-v4.jar
| — LOCAL: bolts-android-1.1.2.jar
— proj.android-studio:gps:unspecified
— LOCAL: google-play-services.jar
debugUnitTest
±-- LOCAL: PluginFacebook.jar
±-- LOCAL: OneSignalSDK.jar
±-- LOCAL: PluginReview.jar
±-- LOCAL: PluginOneSignal.jar
±-- LOCAL: PluginSdkboxAds.jar
±-- LOCAL: sdkbox.jar
±-- LOCAL: PluginAdMob.jar
±-- LOCAL: PluginSdkboxPlay.jar
±-- LOCAL: android-async-http-1.4.8.jar
±-- debug
| ±-- LOCAL: android-async-http-1.4.8.jar
| ±-- LOCAL: OneSignalSDK.jar
| ±-- LOCAL: PluginAdMob.jar
| ±-- LOCAL: PluginFacebook.jar
| ±-- LOCAL: PluginOneSignal.jar
| ±-- LOCAL: PluginReview.jar
| ±-- LOCAL: PluginSdkboxAds.jar
| ±-- LOCAL: PluginSdkboxPlay.jar
| ±-- LOCAL: sdkbox.jar
| ±-- com.facebook.android:facebook_lib:4.6.0
Error:±-- LOCAL: android-support-v4.jar
Error:— LOCAL: bolts-android-1.1.2.jar
| — proj.android-studio:gps:unspecified
| — LOCAL: google-play-services.jar
±-- com.facebook.android:facebook_lib:4.6.0
| ±-- LOCAL: android-support-v4.jar
| — LOCAL: bolts-android-1.1.2.jar
— proj.android-studio:gps:unspecified
— LOCAL: google-play-services.jar
release
±-- LOCAL: PluginFacebook.jar
±-- LOCAL: OneSignalSDK.jar
±-- LOCAL: PluginReview.jar
±-- LOCAL: PluginOneSignal.jar
±-- LOCAL: PluginSdkboxAds.jar
±-- LOCAL: sdkbox.jar
±-- LOCAL: PluginAdMob.jar
±-- LOCAL: PluginSdkboxPlay.jar
±-- LOCAL: android-async-http-1.4.8.jar
±-- com.facebook.android:facebook_lib:4.6.0
| ±-- LOCAL: android-support-v4.jar
| — LOCAL: bolts-android-1.1.2.jar
— proj.android-studio:gps:unspecified
— LOCAL: google-play-services.jar
releaseUnitTest
±-- LOCAL: PluginFacebook.jar
±-- LOCAL: OneSignalSDK.jar
±-- LOCAL: PluginReview.jar
±-- LOCAL: PluginOneSignal.jar
±-- LOCAL: PluginSdkboxAds.jar
±-- LOCAL: sdkbox.jar
±-- LOCAL: PluginAdMob.jar
±-- LOCAL: PluginSdkboxPlay.jar
±-- LOCAL: android-async-http-1.4.8.jar
±-- release
| ±-- LOCAL: android-async-http-1.4.8.jar
| ±-- LOCAL: OneSignalSDK.jar
| ±-- LOCAL: PluginAdMob.jar
| ±-- LOCAL: PluginFacebook.jar
| ±-- LOCAL: PluginOneSignal.jar
| ±-- LOCAL: PluginReview.jar
| ±-- LOCAL: PluginSdkboxAds.jar
| ±-- LOCAL: PluginSdkboxPlay.jar
| ±-- LOCAL: sdkbox.jar
| ±-- com.facebook.android:facebook_lib:4.6.0
Error:±-- LOCAL: android-support-v4.jar
Error:— LOCAL: bolts-android-1.1.2.jar
| — proj.android-studio:gps:unspecified
| — LOCAL: google-play-services.jar
±-- com.facebook.android:facebook_lib:4.6.0
| ±-- LOCAL: android-support-v4.jar
| — LOCAL: bolts-android-1.1.2.jar
— proj.android-studio:gps:unspecified
— LOCAL: google-play-services.jar
Information:BUILD SUCCESSFUL
Information:Total time: 0.796 secs
Information:6 errors
Information:0 warnings
Information:See complete output in console

After adding this following code, now it is working for me.

  1. updated my Application class:

    public class App extends Application {
    @Override
    protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
    }
    }
    2.updated build.gradle file:

    defaultConfig { …

    multiDexEnabled true
    }
    included dependencies:

    dependencies {
    compile ‘com.android.support:multidex:1.0.0’
    }

Thanks for posting the answer, I didn’t realize it’s a multidex issue, usually it has a different error message, that’s good to know

Hi, I am getting the same error.

I did

defaultConfig { ...

multiDexEnabled true
}

and

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

To add MultiDex.install(this); can you tell me where is Application class, do i need to create one?

@nite Can you please make a short instruction page so people can configure this stuff easily and not waste few days in it…

also help me out here…

The complete steps is here.

https://developer.android.com/studio/build/multidex.html