Environment :
OS : Win10 64bits
Qt: 5.12.3
NDK: r18b
JDK: jdk1.8.0_201
I would like to use the tensorflow-lite with Qt5, but there are lots of issues when I try to import the java classes. But how could I download the tensorflow-lite-gpu, tensorflow-lite-cpu and tensorflow-lite-support?
The android studio make this work with 3 lines in the build.gradle, I try to add the 3 lines into the build.gradle too.
dependencies {
// Build off of nightly TensorFlow Lite
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-support:0.0.0-nightly'
}
Error messages
At pastebin since it is long
I can build this example by android studio without any issues, how could I use the java api of tensorflow with Qt?
The answer is quite simple, only need to add a few lines into the build.gradle(from QtCreator, projects(alt+x)->other files->build.gradle)
Put following lines in the "android" block of build.gradle
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
aaptOptions {
noCompress "tflite"
}
Change dependencies block(not the one in the buildscript) of the build.gradle to
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
// Build off of nightly TensorFlow Lite
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-support:0.0.0-nightly'
}
This should do the job, the complete build.gradle looks like
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
repositories {
google()
jcenter()
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
// Build off of nightly TensorFlow Lite
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'
implementation 'org.tensorflow:tensorflow-lite-support:0.0.0-nightly'
// Use local TensorFlow library
// implementation 'org.tensorflow:tensorflow-lite-local:0.0.0'
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
aaptOptions {
noCompress "tflite"
}
lintOptions {
abortOnError false
}
}
Related
I am trying to use Qt AndroidExtras. I found an Android example of the functionality need for me (on java) and want to transfer it to Qt.
I get error on lines (other imports compile successfully):
import androidx.core.app.ActivityCompat;
import androidx.core.hardware.fingerprint.FingerprintManagerCompat;
error: package androidx.core.app does not exist import androidx.core.app.ActivityCompat;
error: package androidx.core.hardware.fingerprint does not exist import androidx.core.hardware.fingerprint.FingerprintManagerCompat;
This code in AndroidStudio builds without errors and works.
Tried to set properties:
android.useAndroidX=true
android.enableJetifier=true
but it doesn't work
Why is this error occurring and how can I fix it?
Here is my build.gradle file that Qt created:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
}
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion '28.0.3'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['resources']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
tasks.withType(JavaCompile) {
options.incremental = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
abortOnError false
}
// Do not compress Qt binary resources file
aaptOptions {
noCompress 'rcc'
}
defaultConfig {
resConfig "en"
minSdkVersion = qtMinSdkVersion
targetSdkVersion = qtTargetSdkVersion
}
}
The gradle file content is below
apply plugin: 'com.android.library'
ext.artifactId = 'zxing-android-embedded'
dependencies {
compile project.zxingCore
// Optional dependency.
provided 'com.android.support:support-v4:22.0.0'
}
android {
resourcePrefix 'zxing_'
compileSdkVersion project.androidTargetSdk
buildToolsVersion project.androidBuildTools
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src-orig', 'src']
res.srcDirs = ['res-orig', 'res']
assets.srcDirs = ['assets']
}
}
// This is bad practice - we should fix the warnings instead.
lintOptions {
// Android warns about the he and id locale folders. he -> iw is already handled with a
// symlink. TODO: what about id?
disable 'LocaleFolder'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
It gives error Could not find property 'zxingCore' on project ':zxing-android-embedded'. for the compile project.zxingCore
Add the following dependency to your project build.gradle
dependencies {
compile 'com.google.zxing:core:3.2.1'
}
In my project it works fine.
I am trying to install Android-GPU-Image in my project. https://github.com/CyberAgent/android-gpuimage
When I download the source, it's broken down as such:
The github project does not include install instructions (other than a dependency line that didn't work for me) so I am trying to figure out how to install a package like this.
My question is: What is the general name of this 'android-gpuimage' folder in the context of adding it to a project? Is this a Module, Sub-Project, Library-Project or what?
Update
Here is my gradle file
import java.util.regex.Pattern
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
project.ext {
multiarch = false
compileSdkVersion = Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
minSdkVersion = Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion = Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
buildToolsVersion = project.ANDROID_BUILD_TOOLS_VERSION
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
compile project(':CordovaLib')
compile project(':app-FacebookLib')
compile files('libs/universal-image-loader-1.9.3.jar')
compile files('libs/twitter4j-core-4.0.3.jar')
compile files('libs/twitter4j-core-4.0.4-SNAPSHOT.jar')
compile files('libs/Filters.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
versionCode Integer.parseInt("" + getVersionCodeFromManifest() + "0")
}
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
productFlavors {
armv7 {
versionCode defaultConfig.versionCode + 2
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
versionCode defaultConfig.versionCode + 4
ndk {
abiFilters "x86", ""
}
}
all {
ndk {
abiFilters "all", ""
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
def getVersionCodeFromManifest() {
def manifestFile = file(android.sourceSets.main.manifest.srcFile)
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def matcher = pattern.matcher(manifestFile.getText())
matcher.find()
return Integer.parseInt(matcher.group(1))
}
Answer:
Needed to add
repositories {
mavenCentral()
}
To my gradle, the one I already had was in the build script, I needed it outside that scope too.
https://stackoverflow.com/a/16675271/3324388
What you have checked out of github is the entire project , which containes the library project and a sample project showing how to use the library.
To use the library , you would have to include the dependency in gradle as mentioned
dependencies {
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.2.3'
}
The gradle file lets you know what kind of project it is
for example ,a library project would have
apply plugin: 'com.android.library'
and the main application project would have
apply plugin: 'com.android.application'
I have been getting Top level exception in android studio, i am using appcompat and sliding menu library. I know i am getting the exception because of conflict of Android Support Libraries as explained in some of the previous threads in stackoverflow. I have tried All the the methods shown in threads like including configuraion etc.
here is my Build.gradle(root)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
}
allprojects {
repositories {
jcenter()
}
}
Here is my Build.Gradle(App)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
applicationId "com.danaraddi.cprograms"
minSdkVersion 8
targetSdkVersion 21
versionCode 9
versionName "7.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.2'
}
// animations
dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.0#aar'
compile 'com.daimajia.androidanimations:library:1.0.8#aar'
}
// inject views
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.jakewharton:butterknife:5.1.2'
}
dependencies {
// Your other dependencies go here
compile project(':library')
}
Here is my Build.Gradle(Lib - SlidingMenu)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
Here is my Log Cat
Error:Execution failed for task ':app:dexDebug'.
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v7/app/ActionBar$Callback;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
PS : I Have places configuration in root,app build.gradle too , it builds successfully after a clean project and then after the same error.
Add
dexOptions {
preDexLibraries = false
}
instead of
dexOptions {
incremental true
}
to build.gradle file inside the android block
I am running an existing android project on Android Studio 0.6.1 on a Mac but am getting this error:
Build script error, unsupported Gradle DSL method found: 'getProguard()'!
I've tried upgrading to the latest Android Studio but that had the same issue, I've also tried all the solutions described in the following Issue forum: https://code.google.com/p/android/issues/detail?id=72419 as many others seemed to have a similar issue which they have resolved. Namely, updating to SDK tools rev 23.0.2, and downloading the latest adt bundle.
The proguard folder does actually appear in sdk > Tools as well so it's not actually a problem with proguard being missing.
Here is the root build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
And the build.gradle in the main module:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.felixschulze.gradle:gradle-hockeyapp-plugin:1.1+'
}
}
apply plugin: 'android'
apply plugin: 'hockeyApp'
configurations {
apt
}
dependencies {
compile 'com.android.support:support-v4:19.0.+'
FileTree tree = fileTree(dir: 'libs', include: '*.jar');
tree.exclude 'android-support-v4.jar'
compile tree;
apt fileTree(dir: 'compile-libs', include: '*.jar')
compile project(':thirdparty:google-play-services_lib')
compile project(':thirdparty:DaoCore')
compile project(':thirdparty:SlidingMenu-master:library')
compile project(':thirdparty:jump.android:Jump')
compile project(':thirdparty:drag-sort-listview')
compile project(':thirdparty:AndroidHorizontalListView')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src-gen','src','.apt_generated']
resources.srcDirs = ['src-gen','src','.apt_generated']
aidl.srcDirs = ['src-gen','src','.apt_generated']
renderscript.srcDirs = ['src-gen','src','.apt_generated']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
signingConfigs {
releaseSigning {
storeFile file('***')
storePassword ***
keyAlias ***
keyPassword ***
}
}
buildTypes {
release {
signingConfig signingConfigs.releaseSigning
}
}
hockeyapp {
apiToken = "***"
releaseType = 0
notify = 0
status = 2
notesType = 1
notes = "This is an automatic upload"
symbolsDirectory = file("build/symbols/")
mappingFileNameRegex = "R.txt"
}
}
android.applicationVariants.all { variant ->
ext.aptOutput = file(".apt_generated")
ext.aptOutput.deleteDir()
ext.aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.asPath,
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-s', ext.aptOutput
]
}
// clean generated files
task clean(overwrite:true) {
delete fileTree(dir: ".apt_generated")
}
Another developer here has been able to get the project up and running fine on his Windows 8 Desktop with the same version of Android Studio & Gradle so I don't think it could be anything to do with the project itself however.
This is because v1.1 of the HockeyApp plugin is incompatible with v0.11 of the Android Gradle plugin. According to the release notes for HockeyApp (https://github.com/x2on/gradle-hockeyapp-plugin/releases) you should be using 2.1.