如何将Gradle链接到本地Android库并解决';找不到方法externalNativeBuild()';?
我在Android Studio()中尝试构建电报源代码时遇到了一个问题 我已经安装了NDK、CMake、LLDB。 但我有一个错误: “梯度同步失败:找不到方法externalNativeBuild()” 这是我的身材。格雷德尔:如何将Gradle链接到本地Android库并解决';找不到方法externalNativeBuild()';?,gradle,build,telegram,ndk-build,android-native-library,Gradle,Build,Telegram,Ndk Build,Android Native Library,我在Android Studio()中尝试构建电报源代码时遇到了一个问题 我已经安装了NDK、CMake、LLDB。 但我有一个错误: “梯度同步失败:找不到方法externalNativeBuild()” 这是我的身材。格雷德尔: apply plugin: 'com.android.application' repositories { mavenCentral() } configurations { compile.exclude module: 'suppo
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'
[P>似乎Grand还没有链接到C++库。
但是,我不知道如何手动将Gradle链接到Android.mk。
有什么想法吗?一些猜测:
- 确保您正在使用ndk-r12或ndk-r13(检查您的local.properties文件)。更改ndk版本后,rm-fr TMessagesProj/.externalNativeBuild[这是当前android studio所需要的]
- gradle和本机代码之间的唯一连接是已经存在的顶级Android.mk,只需将其路径更改为“jni/Android.mk”[它需要是$project/build.gradle文件的相对路径
- 也许不需要build.gradle中的jniLibs.srcDirs行:除非有其他用途,否则共享库将自动打包到APK中。生成的本机库不会保存在那里
- 确保您正在使用ndk-r12或ndk-r13(检查您的local.properties文件)。更改ndk版本后,请使用rm-fr TMessagesProj/.externalNativeBuild[当前android studio需要此版本]
- gradle和本机代码之间的唯一连接是已经存在的顶级Android.mk,只需将其路径更改为“jni/Android.mk”[它需要是$project/build.gradle文件的相对路径
- 也许不需要build.gradle中的jniLibs.srcDirs行:除非有其他用途,否则共享库将自动打包到APK中。生成的本机库不会保存在那里
我确实安装了cmake,不确定这是否重要。您的项目可以使用我的伪json文件进行构建,因此您的系统应该非常接近。非常有用!非常感谢,我将尝试此。:)非常有用!非常感谢,我将尝试此。:)