Lorenzo Sciandra 7ea4ced223 Update build.gradle
Quick fix that would make the project ready for gradle 2.3. I've tested it both with gradle 2.2.3 and 2.3, worked well in both.

[Reference](https://stackoverflow.com/questions/42644226/no-sdkhandler-field-in-libraryplugin-after-updating-to-build-tools-2-3-0)

(reason: I've updated my rn proj to sdk 26, build tools 26 and newer gradle)
2017-08-23 16:22:07 +01:00

156 lines
4.6 KiB
Groovy

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'de.undercouch:gradle-download-task:3.1.2'
}
}
import org.apache.tools.ant.taskdefs.condition.Os
import de.undercouch.gradle.tasks.download.Download
apply plugin: 'de.undercouch.download'
apply plugin: 'com.android.library'
def downloadsDir = new File("$buildDir/downloads")
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
task createNativeDepsDirectories {
downloadsDir.mkdirs()
thirdPartyNdkDir.mkdirs()
}
// Custom task for NDK module
def getNdkBuildName() {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return "ndk-build.cmd"
} else {
return "ndk-build"
}
}
def findNdkBuildFullPath() {
// we allow to provide full path to ndk-build tool
if (hasProperty('ndk.command')) {
return property('ndk.command')
}
// or just a path to the containing directory
if (hasProperty('ndk.path')) {
def ndkDir = property('ndk.path')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
if (System.getenv('ANDROID_NDK') != null) {
def ndkDir = System.getenv('ANDROID_NDK')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
def ndkDir = android.hasProperty('plugin') ? android.plugin.ndkFolder :
project.android.ndkDirectory.absolutePath
if (ndkDir) {
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
return null
}
def getNdkBuildFullPath() {
def ndkBuildFullPath = findNdkBuildFullPath()
if (ndkBuildFullPath == null) {
throw new GradleScriptException(
"ndk-build binary cannot be found, check if you've set " +
"\$ANDROID_NDK environment variable correctly or if ndk.dir is " +
"setup in local.properties",
null)
}
if (!new File(ndkBuildFullPath).canExecute()) {
throw new GradleScriptException(
"ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" +
"Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.proerties, is set correctly.\n" +
"(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)",
null)
}
return ndkBuildFullPath
}
task downloadJSCHeaders(dependsOn: createNativeDepsDirectories, type: Download) {
// in sync with webkit SVN revision 174650
def jscAPIBaseURL = 'https://raw.githubusercontent.com/WebKit/webkit/38b15a3ba3c1b0798f2036f7cea36ffdc096202e/Source/JavaScriptCore/API/'
def jscHeaderFiles = ['JavaScript.h', 'JSBase.h', 'JSContextRef.h', 'JSObjectRef.h', 'JSRetainPtr.h', 'JSStringRef.h', 'JSValueRef.h', 'WebKitAvailability.h']
def output = new File(downloadsDir, 'jsc')
output.mkdirs()
src(jscHeaderFiles.collect { headerName -> "$jscAPIBaseURL$headerName" })
onlyIfNewer true
overwrite false
dest output
}
task prepareJSC(dependsOn: downloadJSCHeaders) << {
copy {
from {downloadJSCHeaders.dest}
include 'jni/**/*.so', '*.h', 'Android.mk'
filesMatching('*.h', { fname -> fname.path = "JavaScriptCore/${fname.path}"})
into "$thirdPartyNdkDir/jsc";
}
}
task buildEXGLLib(dependsOn: [prepareJSC], type: Exec) {
inputs.file('src/main/jni')
inputs.file('../cpp')
outputs.dir("$buildDir/exgl/all")
commandLine getNdkBuildFullPath(),
'NDK_PROJECT_PATH=null',
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/exgl/all",
"THIRD_PARTY_NDK_DIR=$thirdPartyNdkDir",
'-C', file('src/main/jni').absolutePath,
'--jobs', Runtime.runtime.availableProcessors()
}
task cleanEXGLLib(type: Exec) {
commandLine getNdkBuildFullPath(),
'-C', file('src/main/jni').absolutePath,
'clean'
}
task packageEXGLLibs(dependsOn: buildEXGLLib, type: Copy) {
from "$buildDir/exgl/all"
exclude '**/libjsc.so'
exclude '**/libgnustl_shared.so'
into "$buildDir/exgl/exported"
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
// Use custom task for NDK module from above
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "$buildDir/exgl/exported"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn packageEXGLLibs
}
clean.dependsOn cleanEXGLLib
}
}
repositories {
mavenCentral()
}
dependencies {
compile "com.facebook.react:react-native:+" // From node_modules
}