Tensorflow in Android, gradle issues - android-studio

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.

Related

Android Studio: Error "Failed to resolve: design"?

Hi I receive this error message on gradle project sync.
"Failed to resolve: design"
I can't find what's this.
Is there any friend that can help me with this? Or do you have another icon pack Android Studio project?
It's from CandyBar-Sample-Master android icon pack project.
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.CompileSdk
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def appName = parent.name
def fileName = appName.replace(" ", "_")
outputFileName = "$fileName-v${variant.versionName}.apk"
}
}
defaultConfig {
applicationId "com.grafiman.icons.selero"
minSdkVersion rootProject.ext.MinSdk
targetSdkVersion rootProject.ext.TargetSdk
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.danimahardhika.candybar-library:core:3.5.0-b4'
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
google()
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
}
//NOTE: This is important
rootProject.ext {
BuildTools = "27.0.3"
MinSdk = 15
TargetSdk = 26
CompileSdk = 26
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Android Studio Wikitude Native SDK Issue

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'
}
}
}

Android studio not publishing artifact to Artifactory

I'm facing an odd problem with Android Studio and Artifactory. I want to publish a module from Android Studio. The problem being, the build info is published just fine but the artifacts are not published.
build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.5.4"
}
}
allprojects {
apply plugin: "com.jfrog.artifactory"
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'libs-release'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
module/build.gradle
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
def packageName = 'x.x'
def libraryVersion = 'v1.0.0'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 10000
versionName libraryVersion
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
publishing {
publications {
aar(MavenPublication) {
groupId packageName
version = libraryVersion
artifactId "y"
artifact("$buildDir/outputs/aar/$archivesBaseName-release.aar")
}
}
}
artifactory {
publish {
defaults {
publications('aar')
publishArtifacts = true
publishBuildInfo = false
publishPom = true
publishIvy = false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.8.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
When I run ./gradlew assembleRelease artifactoryPublish from the terminal, I always get the following output:
> Task :minecommon:artifactoryPublish
Deploying build descriptor to: https://artifactory-domain/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under https://artifactory-domain/artifactory/webapp/builds/project-name/1509633107114
BUILD SUCCESSFUL in 2s
26 actionable tasks: 1 executed, 25 up-to-date
I can find the build in the "Build Browser" of my Artifactory.
Is there something wrong with my configuration? How can I make gradle publish my artifacts?
I've tries every article I could find on this issue to no resolve.

Use renderscript with gradle experimental

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

Robotium in Android Studio with Cucumber

I have been trying to integrate Cucumber(java) with Robotium to add BDD to android tests in the Android studio. Unfortunately i am getting stuck trying to run the Cucumber features as it is not able to identify the step definitions.
My folder structure is as below:
ParentProject
|
Module
|
src
|
instrumentTest
|
java(this is the source root in build.gradle)
|
cucumbertests
|
CukeRunner.java
|
steps
|
resources
|
cucumbertests
|
Sample.feature
The above setup works fine in intellij.
My build.gradle in the module is as follows:
buildscript {
dependencies {
repositories {
mavenCentral()
mavenLocal()
}
classpath 'com.android.tools.build:gradle:0.7.3'
}
}
apply plugin: 'android'
dependencies {
repositories {
mavenCentral()
mavenLocal()
}
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.squareup:otto:1.3.4'
compile 'com.squareup.dagger:dagger:1.1.0'
compile 'com.squareup.dagger:dagger-compiler:1.1.0'
compile 'com.squareup.okhttp:okhttp:1.2.1'
compile 'com.squareup.retrofit:retrofit:1.2.1'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.guava:guava:15.0'
compile 'com.google.maps.android:android-maps-utils:0.2.1'
compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
compile fileTree(dir: 'libs', include: '*.jar')
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1'
instrumentTestCompile 'info.cukes:cucumber-android:1.1.5'
instrumentTestCompile 'info.cukes:cucumber-junit:1.1.5'
instrumentTestCompile 'info.cukes:cucumber-picocontainer:1.1.5'
instrumentTestCompile 'info.cukes:gherkin:2.12.2'
}
android {
testBuildType "debug"
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
signingConfigs {
debug {
storeFile file('../certificate/debug.keystore')
}
}
sourceSets {
instrumentTest {
java.srcDirs = ['src/instrumentTest/java','src/instrumentTest/cucumber']
}
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'AndroidRSS/src']
resources.srcDirs = ['src/main/res']
aidl.srcDirs = ['src/main/aidl']
renderscript.srcDirs = ['src/main/rs']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
}
}
Error i get is that Cucumber hasnt been able to detect the step definitions. Since this structure works in intellij i think it may just be different way to be able to have this working in Android studio.
I am trying to have a test work like this https://stackoverflow.com/a/19940625/1165859
My feature file is :
The Feature file run config is :
The cukerunner is
package cucumbertests;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options()
public class cukerunner {
}
Run results i get are:
Inspite of these methods implemented in the cucumbertests.steps
It seems gradle tags are misplaced in build.gradle script file . Please look at below build.gradle file and do the necessary changes.
buildscript {
repositories {
mavenCentral() // This only tells gradle where the to find the android plugin
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.3'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.squareup:otto:1.3.4'
compile 'com.squareup.dagger:dagger:1.1.0'
compile 'com.squareup.dagger:dagger-compiler:1.1.0'
compile 'com.squareup.okhttp:okhttp:1.2.1'
compile 'com.squareup.retrofit:retrofit:1.2.1'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.guava:guava:15.0'
compile 'com.google.maps.android:android-maps-utils:0.2.1'
compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
compile fileTree(dir: 'libs', include: '*.jar')
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1'
instrumentTestCompile 'info.cukes:cucumber-android:1.1.5'
instrumentTestCompile 'info.cukes:cucumber-junit:1.1.5'
instrumentTestCompile 'info.cukes:cucumber-picocontainer:1.1.5'
instrumentTestCompile 'info.cukes:gherkin:2.12.2'
}
android {
testBuildType "debug"
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
signingConfigs {
debug {
storeFile file('../certificate/debug.keystore')
}
}
sourceSets {
instrumentTest {
java.srcDirs = ['src/instrumentTest/java','src/instrumentTest/cucumber']
}
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'AndroidRSS/src']
resources.srcDirs = ['src/main/res']
aidl.srcDirs = ['src/main/aidl']
renderscript.srcDirs = ['src/main/rs']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
}
}
What is there inside src/instrumentTest/cucumber directory. If you have any java classes there I think you have to move then in java directory of test project.
On cucumber github page there's a new implementation of how to use cucumber on Android Studio.
I've tested today and it worked
Check it out: https://github.com/cucumber/cucumber-jvm/tree/master/examples/android/android-studio/Cukeulator
I'll be glad to help if you have any doubts

Resources