I am using this https://github.com/quiet/org.quietmodem.Quiet link to transfer sound. This is a library so added it in project and in buld.gradle , i have compiled the project as :
compile project(':quiet')
My code for build.gradle(Module : quiet) is
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable = true
jniDebuggable = true
}
}
sourceSets { main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []
} }
externalNativeBuild{
ndkBuild{
path "$projectDir/src/main/jni/Android.mk"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:23.0.0'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
compile 'com.android.support:appcompat-v7:23.1.1'
}
def getNdkDir() {
if (System.env.ANDROID_NDK_ROOT != null)
return System.env.ANDROID_NDK_ROOT
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkdir = properties.getProperty('ndk.dir', null)
if (ndkdir == null)
throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")
return ndkdir
}
def getNdkBuildCmd() {
def ndkbuild = getNdkDir() + "/ndk-build"
if (Os.isFamily(Os.FAMILY_WINDOWS))
ndkbuild += ".cmd"
return ndkbuild
}
task ndkBuild(type:Exec, description: "Compile JNI Sources") {
workingDir file('src/main')
commandLine getNdkBuildCmd()
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkLibsToJar
}
task ndkLibsToJar(type: Zip, dependsOn: 'ndkBuild', description: 'Create a JAR of the native libs') {
destinationDir new File(buildDir, 'libs')
baseName 'ndk-libs'
extension 'jar'
from(new File(buildDir, 'libs')) { include '**/*.so' }
into 'lib/'
}
Now when i build my project , it throws ndk issues which is shown in the image
The issue I am facing is shown in the image
Related
i can't sync android project i add gradle code below. When i sync it's failed and add message: Error:Cannot invoke method add() on null object
apply plugin: 'com.android.application'. I tryed everything, but can't fix it
android {
def ci_pf = new File('ci.properties')
if (ci_pf.canRead()) {
def Properties ci_p = new Properties()
ci_p.load(new FileInputStream(ci_pf))
def bld = ci_p['ci_versionCode'].toInteger()
def bvn = ci_p['ci_versionName']
def csv = ci_p['ci_compileSdkVersion'].toInteger()
def btv = ci_p['ci_buildToolsVersion']
def msv = ci_p['ci_minSdkVersion'].toInteger()
def tsv = ci_p['ci_targetSdkVersion'].toInteger()
def cxf = ci_p['ci_cppFlags']
compileSdkVersion csv
buildToolsVersion btv
defaultConfig {
applicationId "com.nordcurrent.AdSystemTest"
minSdkVersion msv
targetSdkVersion tsv
versionCode bld
versionName bvn
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions -Wno-nonportable-include-path -DDEBUG -D_DEBUG " + cxf
cFlags "-D\"lua_getlocaledecpoint()='.'\" -DLUA_ANSI -DUSE_ANDROID"
arguments "-DANDROID_STL=c++_static", "-DANDROID_ARM_MODE=arm", "-DANDROID_ARM_NEON=TRUE"
}
}
ndk {
// Specifies the ABI configurations of your native
// libraries Gradle should build and package with your APK.
abiFilters 'armeabi-v7a', 'x86'
jobs 32
}
}
compileSdkVersion = csv
buildToolsVersion = btv
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled = false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
}
}
}
android.productFlavors {
create("fat") {
ndk.abiFilters.add("armeabi-v7a")
ndk.abiFilters.add("x86")
}
}
android.sources {
main {
jni {
source {
srcDirs 'src/main/jni'
}
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name: 'Millennial', ext: 'aar')
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.google.android.gms:play-services-ads:10.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-annotations:25.2.0'
/** Tune dependency */
compile 'com.android.support:support-v4:23.1.1'
compile 'de.greenrobot:eventbus:2.4.0'
androidTestCompile 'com.android.support:support-annotations:25.2.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
testCompile 'junit:junit:4.12'
compile 'junit:junit:4.12'
}
I'm having trouble getting my NDK to compile properly in Android Studio. Whenever I try running to compile I am getting the following error.
Error:Execution failed for task ':app:ndkBuild'. A problem occurred starting process 'command 'ndk-build.cmd''
build.gradle:-
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.google.android.apps.watchme"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
sourceSets.main{
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
project.ext.versionCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9] //versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + defaultConfig.versionCode
}
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'C:\\Users\\RAM-RAMADEVI\\AppData\\Local\\Android\\sdk\\ndk-bundle', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-plus:7.8.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.google.apis:google-api-services-youtube:v3-rev120-1.19.0'
compile 'com.google.http-client:google-http-client-android:+'
compile 'com.google.api-client:google-api-client-android:+'
compile 'com.google.api-client:google-api-client-gson:+'
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.google.code.gson:gson:2.3'
}
local.properties:-
ndk.dir=C\:\\Users\\RAM-RAMADEVI\\AppData\\Local\\Android\\Sdk\\ndk-bundle
sdk.dir=C\:\\Users\\RAM-RAMADEVI\\AppData\\Local\\Android\\Sd
k
I want to create smth like this in my project, but i'm new to gradle, so i don't know a lot of things it can do.
Here is project structure in explorer
gradle.build from app module
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
}
}
// Manifest version information!
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def date = new Date()
def buildTime = date.format("dd.MM.yy", TimeZone.getTimeZone("UTC"))
def buildTimeInternal = date.format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
buildConfigField "String", "BUILD_TIME", "\"${buildTimeInternal}\""
testApplicationId "ru.ltst.u2020mvp.tests"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
debug {
storeFile file("../distribution/debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release {
storeFile file("../distribution/debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
debug {
applicationIdSuffix '.dev'
versionNameSuffix '-dev'
debuggable true
signingConfig signingConfigs.debug
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
signingConfig signingConfigs.release
}
}
productFlavors {
internal {
applicationId 'ru.ltst.u2020mvp.internal'
}
production {
applicationId 'ru.ltst.u2020mvp'
}
}
lintOptions {
textReport true
textOutput 'stdout'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
// TODO remove eventually: http://b.android.com/162285
configurations {
internalDebugCompile
}
dependencies {
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:support-annotations:23.0.1'
compile "com.android.support:appcompat-v7:23.0.1"
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.google.dagger:dagger:2.0.1'
apt 'com.google.dagger:dagger-compiler:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.picasso:picasso:2.5.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
internalDebugCompile 'com.squareup.retrofit:retrofit-mock:1.9.0'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.jakewharton.timber:timber:2.7.1'
internalDebugCompile 'com.jakewharton.madge:madge:1.1.1'
internalDebugCompile 'com.jakewharton.scalpel:scalpel:1.1.1'
compile 'io.reactivex:rxjava:1.0.8'
compile 'io.reactivex:rxandroid:0.24.0'
internalCompile 'com.mattprecious.telescope:telescope:1.4.0#aar'
// Espresso 2 Dependencies
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude module: 'support-annotations'
}
}
// change apk name
android.applicationVariants.all { variant ->
for (output in variant.outputs) {
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = "u2020-mvp-${output.name}-${buildTime}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
// print build finish time
gradle.buildFinished { buildResult ->
def buildFinishDate = new Date()
def formattedDate = buildFinishDate.format('yyyy-MM-dd HH:mm:ss')
println "Build finished: ${formattedDate}"
}
Can someone explain to me how it works?
When i change build Variant the java content is changed. (e.g it was main, internal,internalDebug for internalDebug variant and then it became main,internal,internalRelease for internalRelease build variants).
The reason I'm asking is that i don't see any "internalRelease" word in gradle file, so i don't understand the logic of how the build variants were created and how it defines what modules to show for different build variants
debug for test without signature and release for publish with signature;click the left-top robot ,and turn android to project , u will understand;
I'm trying to convert any project tango sample app to use the new experimental gradle build system. I downloaded an app, verified that it builds and deploys, and then updated files following the experimental-gradle guide. The process was straight-forward, except for the app build.gradle file, shown below before and after my edits. I have been studying the gradle plugin, the experimental guide, etc, but haven't figured out what to do with sourceSets and the two tasks and keep getting errors. What is the right way to modify build.gradle?
Note:
I used point-cloud-jni-example, but these changes should be the same for any project tango app, because the relevant files are essentially identical for all the tango sample apps.
stock app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.projecttango.experiments.nativepointcloud"
minSdkVersion 19
targetSdkVersion 19
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [];
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build"
commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
modified app build.gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 19
buildToolsVersion = "23.0.0"
defaultConfig.with {
applicationId = "com.projecttango.experiments.nativepointcloud"
minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 19
}
android.sourceSets.main {
jniLibs.srcDir = 'src/main/libs'
jni.srcDirs = [];
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
ndk.with {
debuggable = true
}
}
}
android.ndk {
moduleName = "point_cloud_jni_example"
ldLibs += ["android", "EGL", "GLESv2", "dl", "log"]
stl = "stlport_static"
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build.cmd"
commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I am not sure if it resolves all issues.
In any case, you have to change your buildTypes block using:
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
Also use the last version 0.2.1
I've started using Gradle today and after searching for an hour and trying every possible answer from SO (e.g. 1) and different blogs (e.g. 2) and documentations (e.g. 3) I need some help.
My question is simple: How to execute a custom build-step (in my case the execution of ndk-build with a customized Android.mk) as part of the regular build-process?
The build.gradle looks like this:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "myApp.prototype"
minSdkVersion 16
targetSdkVersion 19
testApplicationId "myApp.prototype.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets.main.jni.srcDirs = []
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def rootDir = project.rootDir
def localProperties = new File(rootDir, "local.properties")
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def ndkDir = properties.getProperty('ndk.dir')
println ndkDir
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkDir\\ndk-build.cmd",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
} else {
commandLine "$ndkDir/ndk-build",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services-location:6.5+'
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.code.gson:gson:2.2.4'
compile fileTree(dir: new File(buildDir, 'libs'), include: '*.jar')
}
When executing gradle ndkBuild from the command-line, everything works fine. But I want that Android Studio automatically runs ndkBuild when it runs the rest of the Android compile procedures (such as generateDebugSources, preBuild, preDebugBuild, ...).
I have tried to attach myself to these events like this:
gradle.projectsEvaluated {
preBuild.dependsOn(ndkBuild)
}
but regardless where I put that code, or what task I use from the variety of tasks available (when running gradle tasks), nothing seems to work.
Have you tried adding a dependency for ndkBuild on JavaCompile tasks ?
android {
...
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}