1

I meet a problem when trying to build Telegram Source Code in Android Studio (https://github.com/DrKLO/Telegram).

I have installed NDK, CMake, LLDB. But I got this error: "Gradle sync failed: Could not find method externalNativeBuild()"

Here is my build.gradle:

    apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

configurations {
    compile.exclude module: 'support-v4'
}

dependencies {
    compile 'com.google.android.gms:play-services-gcm:9.6.1'
    compile 'com.google.android.gms:play-services-maps:9.6.1'
    compile 'com.google.android.gms:play-services-vision:9.6.1'
    compile 'com.android.support:support-core-ui:24.2.1'
    compile 'com.android.support:support-compat:24.2.1'
    compile 'com.android.support:support-core-utils:24.2.1'
    compile 'net.hockeyapp.android:HockeySDK:4.0.1'
    compile 'com.googlecode.mp4parser:isoparser:1.0.6'
}

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.2'

    useLibrary 'org.apache.http.legacy'
    defaultConfig.applicationId = "org.telegram.messenger"

    sourceSets.main.jniLibs.srcDirs = ['./jni/']

    externalNativeBuild {
        ndkBuild {
            path "/jni/Android.mk"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    signingConfigs {
        debug {
            storeFile file("config/release.keystore")
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD

        }

        release {
            storeFile file("config/release.keystore")
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD

        }
    }

    buildTypes {
        debug {
            debuggable true
            jniDebuggable true
            signingConfig signingConfigs.debug
            applicationIdSuffix ".beta"
        }

        release {
            debuggable false
            jniDebuggable false
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        foss {
            debuggable false
            jniDebuggable false
            signingConfig signingConfigs.release
        }
    }

    defaultConfig.versionCode = 851

    sourceSets.debug {
        manifest.srcFile 'config/debug/AndroidManifest.xml'
    }

    sourceSets.release {
        manifest.srcFile 'config/release/AndroidManifest.xml'
    }

    sourceSets.foss {
        manifest.srcFile 'config/foss/AndroidManifest.xml'
    }

    productFlavors {
        x86 {
            ndk {
                abiFilter "x86"
            }
            versionCode = 2
        }
        armv7 {
            ndk {
                abiFilter "armeabi-v7a"
            }
            versionCode = 1
        }
        fat {
            versionCode = 3
        }
    }

    applicationVariants.all { variant ->
        def abiVersion = variant.productFlavors.get(0).versionCode
        variant.mergedFlavor.versionCode = defaultConfig.versionCode * 10 + abiVersion;
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 24
        versionName "3.13.1"

        externalNativeBuild { ndkBuild {
                arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-14"
                abiFilters "armeabi-v7a", "x86"
            }
        }
    }
}

apply plugin: 'com.google.gms.google-services'

It seems the Gradle has not linked to exist C++ library yet. But, I didn't know how I manual link Gradle to exist Android.mk. Any ideas?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
D. Tan
  • 11
  • 2

1 Answers1

0

A few guesses:

  • Make sure you are using ndk-r12 or ndk-r13 (check your local.properties file). After you change ndk version, rm -fr TMessagesProj/.externalNativeBuild [this is needed for current android studio]
  • The only connection between gradle and native code is your top level Android.mk which is there already, just change its path to 'jni/Android.mk' [it needs to be relative path to your $project/build.gradle file.
  • maybe jniLibs.srcDirs line in your build.gradle is not needed: the shared lib will be automatically packed into APK, unless you have other purposes. The built native libs are not saved there

I did have cmake installed, not sure that matters. https://developer.android.com/studio/projects/add-native-code.html. Your project could build with my fake json file, so your system should be pretty close.

Gerry
  • 1,223
  • 9
  • 17