local.properties unused property for custom variables - android-studio

I am setting some local variables for build type signing configs, and it seems to be working. However Intellij (Android Studio) seems to think these variables in my local.properties file are unused.
Is this just one of those "turn off the linter" problems, or is there actually a way to solve this and tell the linter to do it's job correctly?
Example of usage:
local.properties:
storeFile=/home/user/dir/file # <-- says it's unused
storePass=pass1234 # <-- unused
# ...
build.gradle
android {
Properties properties = new Properties()
properties.load(project.rootProject.file("local.properties").newDataInputStream())
signingConfigs {
'release (signed)' {
storeFile file(properties.getProperty('storeFile'))
storePassword properties.getProperty('storePass')
keyAlias properties.getProperty('keyAlias')
keyPassword properties.getProperty('keyPass')
}
}
}

Related

ANDROID GRADLE SYNC

Anyone here knows how to fix this error? I'm trying to sync project with gradle files. Thanks in advance!
Caused by: groovy.lang.MissingPropertyException: Could not get unknown
property 'KEY_ALIAS' for project ':app' of type org.gradle.api.Project
android {
signingConfigs {
config {
keyAlias project.KEY_ALIAS
keyPassword project.KEY_PASSWORD
storeFile file(project.STORE_FILE)
storePassword project.STORE_PASSWORD
}
}

Could not find method externalNativeBuild() for arguments

i'm trying to integrate the ndkBuild functionality into an existing android studio project, using the new android studio 2.2 , in order to enable c++ debugging etc.
i have tried out one of the ndk example projects which android studio 2.2 offers, which works perfectly fine. However, when i try to run the gradle commands in my own project, i get this error message:
Error:(73, 0) Could not find method externalNativeBuild() for arguments [build_c6heui1f67l8o1c3ifgpntw6$_run_closure2$_closure9#4329c1c9] on project ':core' of type org.gradle.api.Project.
By following this description
http://tools.android.com/tech-docs/external-c-builds
i ended up with a gradle script which includes the following commands:
externalNativeBuild{
ndkBuild{
path "$projectDir/jni/Android.mk"
}
}
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK:=$projectDir/jni/Application.mk"
abiFilters "armeabi-v7a", "armeabi","arm64-v8a","x86"
cppFlags "-frtti -fexceptions"
}
}
Did i perhaps miss out on something here with the project setup?
I have set the Android NDK location properly under
File -> Project Structure ... -> SDK Location -> Android NDK location
in my android studio.
Anything else i might have forgotton?
Has anyone run into a similar problem before?
Advice would be much appreciated =)
Just had this error myself. In your root build.gradle, make sure that gradle is set to at least version 2.2.0:
So you should have the following in buildscript {...}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
Suggested by Kun Ming Xies answer, I have separated my cmake part in two to get rid of the annoying error:
Could not find method arguments() for arguments [-DREVISION=1.3.1] on object of type com.android.build.gradle.internal.dsl.CmakeOptions.
The first part in defaultConfig contains the configuration (command line arguments for CMake and C++ flags), and the second contains the path to CMakeLists.txt:
def revision = "1.3.1"
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
versionCode = ...
versionName "${revision}"
externalNativeBuild {
cmake {
arguments "-DREVISION=${revision}"
cppFlags '-fexceptions', '-frtti', '-std=c++11'
}
}
}
buildTypes { }
lintOptions { }
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
}
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang'
}
}
}

Gradle sync error with android.productFlavors setting

I use com.android.tools.build:cradle-experimental:0.7.0.
And want to build only for some abi.
So I set android.productFlavors as below:
productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" #
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters.add("armeabi")
}
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("x86") {
ndk.abiFilters.add("x86")
}
}
I got sync error:Error:Unable to find Android binary with buildType 'debug' and productFlavor '' in project ':xduilib'
I had google for this error message, but no result.
It is ok to only set one platform. why? What's wrong with my setting or product.
Thank you.
Finally, I use this to set target platform.
android.ndk {
moduleName = 'xxx'
abiFilters.addAll(['armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64']) //this is default
ldLibs.addAll(['android', 'log'])
}

Using clang from NDK gradle build system

Using the old Makefile-based Android build system it is possible to using clang to compile sources by adding
NDK_TOOLCHAIN_VERSION=clang
Is there some way to achieve the same thing using the new gradle build system?
It's not directly possible for now, but you can still use the regular Makefiles from gradle:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'android'
android {
...
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set jniLibs directory to ./libs
jni.srcDirs = [] //disable automatic ndk-build call
}
// call regular ndk-build(.cmd) script from main src directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
Newer NDK revisions default to Clang. However, you can explicitly request a toolchain using the -DANDROID_TOOLCHAIN switch.
As of the Android Gradle Plugin 2.2.0 things have become much better. You can also adopt cmake. You should look over the new documentation.
android {
...
defaultConfig {
...
// This block is different from the one you use to link Gradle
// to your CMake or ndk-build script.
externalNativeBuild {
// For ndk-build, instead use ndkBuild {}
cmake {
// Passes optional arguments to CMake.
arguments "-DANDROID_TOOLCHAIN=clang"
// Sets optional flags for the C compiler.
cFlags "-D_EXAMPLE_C_FLAG1", "-D_EXAMPLE_C_FLAG2"
// Sets a flag to enable format macro constants for the C++ compiler.
cppFlags "-D__STDC_FORMAT_MACROS"
}
}
}
buildTypes {...}
productFlavors {
...
demo {
...
externalNativeBuild {
cmake {
...
// Specifies which native libraries to build and package for this
// product flavor. If you don't configure this property, Gradle
// builds and packages all shared object libraries that you define
// in your CMake or ndk-build project.
targets "native-lib-demo"
}
}
}
paid {
...
externalNativeBuild {
cmake {
...
targets "native-lib-paid"
}
}
}
}
// Use this block to link Gradle to your CMake or ndk-build script.
externalNativeBuild {
cmake {...}
// or ndkBuild {...}
}
}

Gradle: one build type based on another

I have 4 build types in Android Studio:
release
debug
kindle
kindle_debug
How is it possible to set the both kindle tasks to use the same data from release/debug and just changing some properties?
You can use initWith to inherit from another BuildType like in this example:
android {
[...]
buildTypes {
debug {
debuggable true
buildConfigField "boolean", "IS_V2", "false"
}
debugV2 {
initWith debug
buildConfigField "boolean", "IS_V2", "true"
applicationIdSuffix ".v2"
}
}
}
}
Then select debugV2 from Build Variants in Android Studio.
See also the docs here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Types

Resources