Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- project.buildDir = 'gradleBuild'
- getProject().setBuildDir('gradleBuild')
- buildscript {
- repositories {
- jcenter()
- google()
- maven {
- url 'https://google.bintray.com/tensorflow'
- }
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.1.0'
- classpath 'org.apache.httpcomponents:httpclient:4.5.4'
- }
- }
- allprojects {
- repositories {
- jcenter()
- google()
- maven {
- url 'https://google.bintray.com/tensorflow'
- }
- }
- }
- // set to 'bazel', 'cmake', 'makefile', 'none'
- def nativeBuildSystem = 'cmake'
- // Controls output directory in APK and CPU type for Bazel builds.
- // NOTE: Does not affect the Makefile build target API (yet), which currently
- // assumes armeabi-v7a. If building with make, changing this will require
- // editing the Makefile as well.
- // The CMake build has only been tested with armeabi-v7a; others may not work.
- def cpuType = 'arm64-v8a'
- // Output directory in the local directory for packaging into the APK.
- def nativeOutDir = 'libs/' + cpuType
- // Default to building with Bazel and override with make if requested.
- def nativeBuildRule = 'buildNativeBazel'
- def demoLibPath = '../../../bazel-bin/tensorflow/examples/android/libtensorflow_demo.so'
- def inferenceLibPath = '../../../bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so'
- // Override for Makefile builds.
- if (nativeBuildSystem == 'makefile') {
- nativeBuildRule = 'buildNativeMake'
- demoLibPath = '../../../tensorflow/contrib/makefile/gen/lib/android_' + cpuType + '/libtensorflow_demo.so'
- inferenceLibPath = '../../../tensorflow/contrib/makefile/gen/lib/android_' + cpuType + '/libtensorflow_inference.so'
- }
- // If building with Bazel, this is the location of the bazel binary.
- // NOTE: Bazel does not yet support building for Android on Windows,
- // so in this case the Makefile build must be used as described above.
- def bazelLocation = '/usr/bin/bazel-real'
- // import DownloadModels task
- project.ext.ASSET_DIR = projectDir.toString() + '/assets'
- project.ext.TMP_DIR = project.buildDir.toString() + '/downloads'
- apply plugin: 'com.android.application'
- android {
- compileSdkVersion 27
- buildToolsVersion '27.0.3'
- if (nativeBuildSystem == 'cmake') {
- defaultConfig {
- applicationId = 'org.tensorflow.demo'
- minSdkVersion 26
- targetSdkVersion 27
- multiDexEnabled true
- ndk {
- abiFilters "${cpuType}"
- }
- externalNativeBuild {
- cmake {
- arguments '-DANDROID_TOOLCHAIN=gcc', '-DANDROID_STL=gnustl_static'
- }
- }
- }
- externalNativeBuild {
- cmake {
- path './jni/CMakeLists.txt'
- }
- }
- //deeplearning4J on Android
- packagingOptions {
- exclude 'META-INF/DEPENDENCIES'
- exclude 'META-INF/DEPENDENCIES.txt'
- exclude 'META-INF/LICENSE'
- exclude 'META-INF/LICENSE.txt'
- exclude 'META-INF/license.txt'
- exclude 'META-INF/NOTICE'
- exclude 'META-INF/NOTICE.txt'
- exclude 'META-INF/notice.txt'
- exclude 'META-INF/INDEX.LIST'
- }
- }
- lintOptions {
- abortOnError false
- }
- dexOptions {
- javaMaxHeapSize "2048M"
- }
- sourceSets {
- main {
- if (nativeBuildSystem == 'bazel' || nativeBuildSystem == 'makefile') {
- // TensorFlow Java API sources.
- java {
- srcDir '../../java/src/main/java'
- exclude '**/examples/**'
- }
- // Android TensorFlow wrappers, etc.
- java {
- srcDir '../../contrib/android/java'
- }
- }
- // Android demo app sources.
- java {
- srcDir 'src'
- }
- manifest.srcFile 'AndroidManifest.xml'
- resources.srcDirs = ['src']
- aidl.srcDirs = ['src']
- renderscript.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = [project.ext.ASSET_DIR]
- jniLibs.srcDirs = ['libs']
- }
- debug.setRoot('build-types/debug')
- release.setRoot('build-types/release')
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- }
- task buildNativeBazel(type: Exec) {
- workingDir '../../..'
- commandLine bazelLocation, '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 buildNativeMake(type: Exec) {
- environment "NDK_ROOT", android.ndkDirectory
- // Tip: install ccache and uncomment the following to speed up
- // builds significantly.
- environment "CC_PREFIX", 'ccache'
- workingDir '../../..'
- commandLine 'tensorflow/contrib/makefile/build_all_android.sh', \
- '-s', \
- 'tensorflow/contrib/makefile/sub_makefiles/android/Makefile.in', \
- '-t', \
- 'libtensorflow_inference.so libtensorflow_demo.so all' \
- , '-a', cpuType \
- // , '-T' // Uncomment to skip protobuf and speed up subsequent builds.
- }
- task copyNativeLibs(type: Copy) {
- from demoLibPath
- from inferenceLibPath
- into nativeOutDir
- duplicatesStrategy = 'include'
- dependsOn nativeBuildRule
- fileMode 0644
- }
- tasks.whenTaskAdded { task ->
- if (nativeBuildSystem == 'bazel' || nativeBuildSystem == 'makefile') {
- if (task.name == 'assembleDebug') {
- task.dependsOn 'copyNativeLibs'
- }
- if (task.name == 'assembleRelease') {
- task.dependsOn 'copyNativeLibs'
- }
- }
- }
- // Download default models; if you wish to use your own models then
- // place them in the "assets" directory and comment out this line.
- //apply from: "download-models.gradle"
- configurations {
- // compile {
- compile.exclude module: 'jcip-annotations'
- compile.exclude module: 'jsr305'
- // transitive = false
- // }
- }
- dependencies {
- implementation 'com.google.code.findbugs:annotations:3.0.1', {
- // Need to exclude these, or build is broken by:
- // com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull
- // exclude module: 'jcip-annotations'
- // exclude module: 'jsr305'
- }
- implementation 'org.projectlombok:lombok:1.16.16'
- annotationProcessor "org.projectlombok:lombok:1.16.16"
- implementation 'org.deeplearning4j:deeplearning4j-core:0.9.1'
- implementation 'org.nd4j:nd4j-native:0.9.1'
- implementation 'org.nd4j:nd4j-native:0.7.2:android-x86'
- if (nativeBuildSystem == 'cmake' || nativeBuildSystem == 'none') {
- implementation 'org.tensorflow:tensorflow-android:+'
- }
- implementation 'com.android.support.constraint:constraint-layout:1.0.2'
- implementation 'com.android.support:support-v4:27.1.0'
- implementation 'com.android.support:support-v13:27.1.0'
- implementation 'com.android.support:cardview-v7:27.1.0'
- implementation 'com.android.support:appcompat-v7:27.1.0'
- //For Splitting the video into images.
- implementation 'nl.bravobit:android-ffmpeg:1.1.2'
- //For Dependency Injection
- implementation 'com.google.dagger:dagger:2.12'
- annotationProcessor 'com.google.dagger:dagger-compiler:2.12'
- //For ViewBinding
- implementation 'com.jakewharton:butterknife:8.8.1'
- annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
- //rest interactions
- implementation 'com.squareup.retrofit2:retrofit:2.4.0'
- //JSON Parsing
- implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
- implementation 'com.google.code.gson:gson:2.8.2'
- //http logging
- implementation 'com.squareup.okhttp3:logging-interceptor:3.4.2'
- //For Deleting all videos in a directory
- implementation 'commons-io:commons-io:2.6'
- //TODO Somehow get deeplearn4j to work in this build file
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement