I'm developing an application for android in the image processing area. Thus, I need high performance. Part of the code is written in NDK and elsewhere in Renderscript. However, I can not compile the application due to ScriptC_ files are not being generated.
My rs files are in the folder ... \ app \ src \ main \ rs
And the raw folder was created in the \ res
Follow the gradle file (app):
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 22
buildToolsVersion = "22.0.1"
defaultConfig.with {
applicationId = "com.google.sample.helloandroidjni"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
//habilita o renderscript no projeto
renderscriptTargetApi = 18
renderscriptSupportModeEnabled = true
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-android.txt'))
}
}
// ldLibs = ["android", "jnigraphics", <other ndk libraries you might need>] --> Compila as classe necessarias no codigo c
android.ndk {
moduleName = "ibmphotophun"
ldLibs.addAll(["android", "EGL", "GLESv2", "dl", "log", "z", "jnigraphics"]) //adicao de bibliotecas nativas em c do NDK android
debuggable = true
}
android.productFlavors {
create("arm") {
ndk.abiFilters.add("armeabi")
}
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
create("x86") {
ndk.abiFilters.add("x86")
}
create("x86-64") {
ndk.abiFilters.add("x86_64")
}
create("mips") {
ndk.abiFilters.add("mips")
}
create("mips-64") {
ndk.abiFilters.add("mips64")
}
create("all")
}
}
//repositories {
// maven {
// url 'https://raw.github.com/vRallev/mvn-repo/master/'
// }
//}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile files('libs/droidText.0.4.jar')
compile files('libs/brimage.jar')
}
Try to rename "rs" folder to "renderscript". It looks like gradle-experimental uses this folder for renderscript code. Helped me to solve this issue with gradle-experimental:0.7.0-beta1
Related
So im trying to first build a basic app using android studio and Wikitudes Native SDK to make an AR app. After following the setup instructions ive ran into an error I cant seem to solve but have an idea of why/where its happening. Does anyone know what could be causing these errors?
This image here shows the errors I am getting and what looks to be an issue with a few of the imports
Here is also a copy of my build.gradle file (Module: app), and my build.gradle file (Module: NativeSDKExamples), respectively:
apply plugin: 'com.android.application'
android {
compileSdkVersion commonCompileSdkVersion
buildToolsVersion commonBuildToolsVersion
defaultConfig {
applicationId "com.uhg.ent.mobile.lifesciences.amplify"
minSdkVersion commonMinSdkVersion
targetSdkVersion commonTargetSdkVersion
versionCode 1
versionName "7.2.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = "app-" + variant.buildType.name + ".apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
flavorDimensions "arch"
productFlavors {
arm7 {
dimension "arch"
}
arm8 {
dimension "arch"
}
x86 {
dimension "arch"
}
allarchs {
dimension "arch"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile (name: 'wikitude-native-sdk', ext:'aar')
arm7Compile project(path: ':plugins', configuration: 'arm7Release')
arm8Compile project(path: ':plugins', configuration: 'arm8Release')
x86Compile project(path: ':plugins', configuration: 'x86Release')
allarchsCompile project(path: ':plugins', configuration: 'allarchsRelease')
compile "com.android.support:appcompat-v7:$commonSupportLibVersion"
compile "com.android.support:design:$commonSupportLibVersion"
compile "com.android.support:support-v4:$commonSupportLibVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android:flexbox:0.2.5'
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
AND
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
subprojects {
ext.commonCompileSdkVersion = 26
ext.commonBuildToolsVersion = "26.0.0"
ext.commonMinSdkVersion = 19
ext.commonTargetSdkVersion = 26
ext.commonSupportLibVersion = "26.0.0"
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
I am trying to get tensorflow in working android, kinda out of default project folder. I modified my build.gradle, but obviously I miss something, as my app crashes on runtime complying about unavailabiltity of native libraries. I have spent good few hours tring to solve this, but to no avail. Could someone help, please?
Basically, i compared .so file in APK produced by working tf demo and my .so, and they are different. So I suppose must me somewhere in my script...
def bazel_location = '/usr/local/bin/bazel'
def tf_location = '/home/poborak/SW/tensorflow-master'
def cpuType = 'armeabi-v7a'
def nativeDir = 'src/main/jniLibs/' + cpuType
project.buildDir = 'gradleBuild'
getProject().setBuildDir('gradleBuild')
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "bazinac.aplikacenahouby"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', tf_location+'/tensorflow/contrib/android/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
jniLibs.srcDirs = ['src/main/jniLibs']
jni.srcDirs = []
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
testCompile 'junit:junit:4.12'
compile 'org.apache.commons:commons-io:1.3.2'
}
task buildNative(type:Exec) {
workingDir tf_location
commandLine bazel_location, 'build', '-c', 'opt', \
'tensorflow/examples/android:tensorflow_native_libs', \
'--crosstool_top=//external:android/crosstool', \
'--cpu=' + cpuType, \
'--host_crosstool_top=#bazel_tools//tools/cpp:toolchain'
}
task copyNativeLibs(type: Copy) {
from(tf_location+'bazel-bin/tensorflow/examples/android') { include '**/*.so' }
into nativeDir
duplicatesStrategy = 'include'
}
copyNativeLibs.dependsOn buildNative
assemble.dependsOn copyNativeLibs
Finally I have found workaround. It is to downgrade Gradle to 2.14.xx and Android Plugin Version 2.1.3. Then I have appended assembleDebug.dependsOn copyNativeLibs and it works now. Still I would be interested in better solution of course. (AssembleDebug property is not recognized in newer APV.
As part of an Android app that uses the NDK, I need to export some constants from the C/C++ world into Java. For obvious reasons, I'd rather have this automated. I'm using Android Studio with the NDK support.
How can I generate some .java file on the fly from a shell script that would be ran by Gradle whenever the app builds? Ideally this .java file would go in an build intermediaries directory somewhere and wouldn't have to be in the app source directory.
As an example, the shell script would generate this Java source:
public enum Type {
FOO,
BAR
}
from this C++ source:
enum class Type {
FOO,
BAR
}
For reference here's a simplified version of the Gradle file I'm starting from in Android Studio:
apply plugin: 'com.android.model.application'
model {
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "..."
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 23
}
defaultConfig.multiDexEnabled = true
}
android.ndk {
platformVersion = "18"
moduleName = "jni"
...
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
ndk.with {
CFlags.add("-Werror")
cppFlags.add("-Werror")
}
}
}
android.productFlavors {
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
}
}
repositories {
...
}
dependencies {
...
}
apply plugin: 'com.google.gms.google-services'
You could just write the generated file to the $buildDir/generatedJava then add that directory as a source folder. Then make the task javaCompile depend on your task that generates the source. Something like this could be used inside a build.gradle
def outputJavaFile = new File("$buildDir.absolutePath/generatedJava", 'MyEnum.java')
task generateSources(type: Exec) {
def source = $/
package com.example;
public enum Something {
One,
Two
}
/$
if (!outputJavaFile.parentFile.exists()) {
outputJavaFile.parentFile.mkdirs()
}
outputJavaFile.withWriter {
it << source
}
}
compileJava.dependsOn outputJavaFile
sourceSets {
main {
java {
srcDirs 'src/main/java', outputJavaFile.absolutePath
}
}
}
// if the goal is to generate the source from a script then just call the script
// inside the Exec closure
task shellScriptToGenerateSources(type: Exec) {
commandLine 'myShellScript.sh'
}
// then make compileJava depend on the task that runs the script
compileJava.dependsOn shellScriptToGenerateSources
Edit: To apply the same logic to your updated build.gradle file might look something like this
apply plugin: 'com.android.model.application'
// define an output folder for our generated .java files
def GENERATED_JAVA_OUTPUT = "$buildDir/generatedJava"
// if the goal is to generate the source from a script then just call the script
// inside the Exec closure
task shellScriptToGenerateSources(type: Exec) {
commandLine 'myShellScript.sh'
}
// then make compileJava depend on the task that runs the script
compileJava.dependsOn shellScriptToGenerateSources
model {
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "..."
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 23
}
defaultConfig.multiDexEnabled = true
}
android.ndk {
platformVersion = "18"
moduleName = "jni"
...
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
ndk.with {
CFlags.add("-Werror")
cppFlags.add("-Werror")
}
}
}
android.productFlavors {
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
}
// let android know that our java sources shoudl also consider the generated java for the compiler
android.sourceSet {
main {
java {
srcDir(GENERATED_JAVA_OUTPUT)
}
}
}
}
repositories {
...
}
dependencies {
...
}
apply plugin: 'com.google.gms.google-services'
I made a very hello world with Android Studio NDK. As instructed from http://tools.android.com/tech-docs/new-build-system/gradle-experimental, I copied exactly the same (left only some newer build tool version), but the error always appears:
Error:(49, 1) A problem occurred evaluating project ':app'.
Could not find method testCompile() for arguments [junit:junit:4.12] on project ':app'.
Could you tell me what's problem with my HelloWorld?
Here's my app build.gradle
apply plugin: "com.android.model.application"
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig.with {
applicationId = "com.android.services.testjni"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
buildConfigFields.with {
create() {
type = "int"
name = "VALUE"
value = "1"
}
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file("proguard-rules.pro"))
}
}
android.productFlavors {
create("flavor1") {
applicationId = "com.app"
}
}
// Configures source set directory.
android.sources {
main {
java {
source {
srcDir "src"
}
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
and build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle-experimental:0.2.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and gradle-wrapper.properties
#Fri Nov 27 17:00:16 ICT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
AFAIK, android plugin doesn't have a testCompile configuration, which is one from gradle's java plugin, but has an androidTestCompile. So, you have to rename it in your dependencies, as:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
In don't quite understand why this is failing to compile. When i compile and run the same source code from Eclipse, it compiles and runs perfectly fine. But under Android Studio and Gradle, it just falls apart.
Below is my build.gradle
apply plugin: 'android'
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
jni.srcDirs = []
resources.srcDirs = ['src/main/res']
jniLibs.srcDirs = ['src/main/libs']
}
instrumentTest {
java.srcDirs = ['src/instrumentTest/java']
}
}
/*
productFlavors {
playstore {
packageName '<package name>'
}
amazonappstore {
packageName '<package name>'
}
samsungstore {
packageName '<package name>'
}
}*/
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
ndk{
abiFilter "all"
}
}
buildTypes {
//build type 3
release {
debuggable false
jniDebugBuild false
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
applicationVariants.all { variant ->
def file = variant.outputFile
variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
//TASKS
tasks.withType(com.android.build.gradle.tasks.PackageApplication){
pkgTask -> pkgTask.jniFolders = [new File(projectDir, "libs")]
}
task ndkBuild(type:Exec){
logger.info('ndkBuild Configuration')
def ndkBuild;
def ndkBuildingDir = new File("src/main");
def hasNdk = false;
logger.info('Project Path: ' +projectDir)
logger.info('JNI Path: ' +ndkBuildingDir)
if (System.env.ANDROID_NDK_HOME != null) {
hasNdk = true;
ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
}
else
{
//if env variable is not defined then do this
def Properties localProps = new Properties()
localProps.load(new FileInputStream(file('../local.properties')))
if (localProps['ndk.dir'] !=null)
{
hasNdk = true;
ndkBuild = new File(localProps['ndk.dir'], 'ndk-build')
}
}
commandLine ndkBuild, "--directory", ndkBuildingDir
doFirst {
if (!hasNdk) {
logger.error("Failed NDK build")
}
assert hasNdk : "ANDROID_NDK_HOME not set."
}
}
task copyNativeLibs(type: Copy, dependsOn: "ndkBuild") {
logger.error("Path is"+buildDir);
from(new File('src/main/libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Here is few of the error messages
:app:ndkBuild
JNI LOCATION: jni
MAKE_FILE_LOCATION:
ZLIB Compiled
libpng compiling
make: Entering directory `/Users/vikramsahai/Documents/workspace/SVS-ANDROID/SVS/app/src/main'
Install : libharu.so => libs/armeabi/libharu.so
make: Leaving directory `/Users/vikramsahai/Documents/workspace/SVS-ANDROID/SVS/app/src/main'
:app:compileDebugJava
cast to Object for a varargs call
/Users/vikramsahai/Documents/workspace/SVS-ANDROID/SVS/app/src/main/java/com/vikramsahai/apps/finance/CPDF.java:255: error: cannot access Color
a1.setBackgroundColor(new BaseColor(0xD4D4D4));
^
class file for java.awt.Color not found
cast to Object[] for a non-varargs call and to suppress this warning
/app/src/main/java/com/vikramsahai/apps/finance/db/Database.java:329: warning: non-varargs call of varargs method with inexact argument type for last parameter;
initialValues.put(f.getName().substring(1, f.getName().length()), String.valueOf(m.invoke(obj, null)));
It doesn't make sense why it would compile and run on eclipse and yet fall apart on Android Studio/Gradle
The top level build.gradle has this dependency
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}