In passato ho usato eclipse per progetti NDK, il file Android.mk era perfettamente adatto per compilare l'NDK con livello API 9 mentre si lasciava compilare l'app (SDK) Livello API 22. Ma sembra che ciò non sia possibile quando si utilizza il sistema di build Gradle sperimentale (2.5) con Android Studio 1.3 RC1.Gradle: modifica NDK build target indipendente dall'obiettivo di build SDK
Cosa posso fare per compilare SOLO l'NDK al livello API 9?
mio tipico file Android.mk assomiglia a questo:
APP_PLATFORM := android-9
APP_STL := stlport_static
APP_ABI := all
# Enable c++11 extentions in source code
APP_CPPFLAGS += -std=c++11
#Enable optimalization in release mode
APP_OPTIM := release
mio nuovo file Gradle assomiglia a questo:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 22
buildToolsVersion = "23.0.0 rc3"
defaultConfig.with {
applicationId = "com.example"
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "1.0"
}
}
android.ndk {
moduleName = "NativeLibrary"
cppFlags += "-I${file("src/main/jni/some_folder")}".toString()
cppFlags += "-std=c++11"
//What should be added here to compile the NDK on API 9???
CFlags += "-DNDEBUG"
CFlags += "-fvisibility=hidden"
cppFlags += "-fvisibility=hidden"
ldLibs += ["log"]
stl = "stlport_static"
}
android.buildTypes {
release {
isMinifyEnabled = true
proguardFiles += file('D:/path/proguard-rules.pro')
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.2.0'
}
ho studiato la fonte Gradle e sembra che l'NDK costruire bersaglio è hard-coded lo stesso di compileSdkVersion. Esiste un metodo per evitare o modificare questo comportamento?
NdkCompile.groovy (rendere la creazione di file)
// target
IAndroidTarget target = getPlugin().loadedSdkParser.target
if (!target.isPlatform()) {
target = target.parent
}
commands.add("APP_PLATFORM=" + target.hashString())
Sdk.groovy (bersaglio è la forma inverosimile la compileSdkVersion)
public SdkParser loadParser() {
checkNotNull(extension, "Extension has not been set")
// call getParser to ensure it's created.
SdkParser theParser = getParser()
if (!isSdkParserInitialized) {
String target = extension.getCompileSdkVersion()
if (target == null) {
throw new IllegalArgumentException("android.compileSdkVersion is missing!")
}
FullRevision buildToolsRevision = extension.buildToolsRevision
if (buildToolsRevision == null) {
throw new IllegalArgumentException("android.buildToolsVersion is missing!")
}
theParser.initParser(target, buildToolsRevision, logger)
isSdkParserInitialized = true
}
return theParser
}
Infatti, hanno finalmente fatto questo aggiornamento! –