|
| 1 | + |
| 2 | +// Top-level build file where you can add configuration options common to all sub-projects/modules. |
| 3 | + |
| 4 | +buildscript { |
| 5 | + repositories { |
| 6 | + jcenter() |
| 7 | + maven { |
| 8 | + url 'https://maven.google.com/' |
| 9 | + name 'Google' |
| 10 | + } |
| 11 | + } |
| 12 | + dependencies { |
| 13 | + classpath 'com.android.tools.build:gradle:3.0.0' |
| 14 | + |
| 15 | + // NOTE: Do not place your application dependencies here; they belong |
| 16 | + // in the individual module build.gradle files |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +allprojects { |
| 21 | + repositories { |
| 22 | + jcenter() |
| 23 | + maven { |
| 24 | + url 'https://maven.google.com/' |
| 25 | + name 'Google' |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +project.ext.ASSET_DIR = projectDir.toString() + '/assets' |
| 33 | +def bazelLocation = '/usr/local/bin/bazel' |
| 34 | +def nativeBuildSystem = 'cmake' |
| 35 | + |
| 36 | +// Controls output directory in APK and CPU type for Bazel builds. |
| 37 | +// NOTE: Does not affect the Makefile build target API (yet), which currently |
| 38 | +// assumes armeabi-v7a. If building with make, changing this will require |
| 39 | +// editing the Makefile as well. |
| 40 | +// The CMake build has only been tested with armeabi-v7a; others may not work. |
| 41 | +//def cpuType = 'armeabi-v7a' |
| 42 | +def cpuType = 'arm64-v8a' |
| 43 | +//def cpuType = 'x86_64' |
| 44 | + |
| 45 | +// Output directory in the local directory for packaging into the APK. |
| 46 | +def nativeOutDir = 'libs/' + cpuType |
| 47 | + |
| 48 | +// Default to building with Bazel and override with make if requested. |
| 49 | +def nativeBuildRule = 'buildNativeBazel' |
| 50 | +def demoLibPath = '/home/irina/tensorflow/bazel-bin/tensorflow/examples/android/libtensorflow_demo.so' |
| 51 | +def inferenceLibPath = '/home/irina/tensorflow/bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so' |
| 52 | +if (nativeBuildSystem == 'makefile') { |
| 53 | + nativeBuildRule = 'buildNativeMake' |
| 54 | + demoLibPath = '/home/irina/tensorflow/tensorflow/contrib/makefile/gen/lib/libtensorflow_demo.so' |
| 55 | + inferenceLibPath = '/home/irina/tensorflow/tensorflow/contrib/makefile/gen/lib/libtensorflow_inference.so' |
| 56 | +} |
| 57 | + |
| 58 | +apply plugin: 'com.android.application' |
| 59 | + |
| 60 | +android { |
| 61 | + compileSdkVersion 27 |
| 62 | + buildToolsVersion "26.0.2" |
| 63 | + |
| 64 | + if (nativeBuildSystem == 'cmake') { |
| 65 | + defaultConfig { |
| 66 | + applicationId = 'com.irina.tensorflowexample' |
| 67 | + versionCode 1 |
| 68 | + versionName "1.0" |
| 69 | + minSdkVersion 21 |
| 70 | + targetSdkVersion 27 |
| 71 | + ndk { |
| 72 | + abiFilters "${cpuType}" |
| 73 | + } |
| 74 | + externalNativeBuild { |
| 75 | + cmake { |
| 76 | + arguments '-DANDROID_TOOLCHAIN=gcc', '-DANDROID_STL=gnustl_static' |
| 77 | + cppFlags "-std=c++11" |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + externalNativeBuild { |
| 82 | + cmake { |
| 83 | + path './jni/CMakeLists.txt' |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + buildTypes { |
| 88 | + release { |
| 89 | + minifyEnabled false |
| 90 | + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 91 | + } |
| 92 | + } |
| 93 | + lintOptions { |
| 94 | + abortOnError false |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | + compileOptions { |
| 99 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 100 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 101 | + } |
| 102 | + |
| 103 | + sourceSets { |
| 104 | + main { |
| 105 | + if (nativeBuildSystem == 'bazel' || nativeBuildSystem == 'makefile') { |
| 106 | + // TensorFlow Java API sources. |
| 107 | + java { |
| 108 | + srcDir '/home/irina/tensorflow/tensorflow/java/src/main/java' |
| 109 | + exclude '**/examples/**' |
| 110 | + } |
| 111 | + |
| 112 | + // Android TensorFlow wrappers, etc. |
| 113 | + java { |
| 114 | + srcDir '/home/irina/tensorflow/tensorflow/contrib/android/java' |
| 115 | + } |
| 116 | + } |
| 117 | + // Android demo app sources. |
| 118 | + java { |
| 119 | + srcDir 'src' |
| 120 | + } |
| 121 | + |
| 122 | + manifest.srcFile 'AndroidManifest.xml' |
| 123 | + resources.srcDirs = ['src'] |
| 124 | + aidl.srcDirs = ['src'] |
| 125 | + renderscript.srcDirs = ['src'] |
| 126 | + res.srcDirs = ['res'] |
| 127 | + assets.srcDirs = [project.ext.ASSET_DIR] |
| 128 | + jniLibs.srcDirs = ['libs','jni'] |
| 129 | + } |
| 130 | + |
| 131 | + debug.setRoot('build-types/debug') |
| 132 | + release.setRoot('build-types/release') |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +task buildNativeBazel(type: Exec) { |
| 137 | + workingDir '/home/irina/tensorflow' |
| 138 | + commandLine bazelLocation, 'build', '-c', 'opt', \ |
| 139 | + 'tensorflow/examples/android:tensorflow_native_libs', \ |
| 140 | + '--crosstool_top=//external:android/crosstool', \ |
| 141 | + '--cpu=' + cpuType, \ |
| 142 | + '--host_crosstool_top=@bazel_tools//tools/cpp:toolchain' |
| 143 | +} |
| 144 | + |
| 145 | +task buildNativeMake(type: Exec) { |
| 146 | + environment "NDK_ROOT", android.ndkDirectory |
| 147 | + // Tip: install ccache and uncomment the following to speed up |
| 148 | + // builds significantly. |
| 149 | + // environment "CC_PREFIX", 'ccache' |
| 150 | + workingDir '/home/irina/tensorflow' |
| 151 | + commandLine 'tensorflow/contrib/makefile/build_all_android.sh', \ |
| 152 | + '-s', \ |
| 153 | + 'tensorflow/contrib/makefile/sub_makefiles/android/Makefile.in', \ |
| 154 | + '-t', \ |
| 155 | + 'libtensorflow_inference.so libtensorflow_demo.so' \ |
| 156 | + //, '-T' // Uncomment to skip protobuf and speed up subsequent builds. |
| 157 | +} |
| 158 | + |
| 159 | +task copyNativeLibs(type: Copy) { |
| 160 | + from demoLibPath |
| 161 | + from inferenceLibPath |
| 162 | + into nativeOutDir |
| 163 | + duplicatesStrategy = 'include' |
| 164 | + dependsOn nativeBuildRule |
| 165 | + fileMode 0644 |
| 166 | +} |
| 167 | + |
| 168 | +tasks.whenTaskAdded { task -> |
| 169 | + if (nativeBuildSystem == 'bazel' || nativeBuildSystem == 'makefile') { |
| 170 | + if (task.name == 'assembleDebug') { |
| 171 | + task.dependsOn 'copyNativeLibs' |
| 172 | + } |
| 173 | + if (task.name == 'assembleRelease') { |
| 174 | + task.dependsOn 'copyNativeLibs' |
| 175 | + } |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +dependencies { |
| 180 | + compile fileTree(include: ['*.jar'], dir: 'libs') |
| 181 | + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { |
| 182 | + exclude group: 'com.android.support', module: 'support-annotations' |
| 183 | + }) |
| 184 | + compile 'com.android.support.constraint:constraint-layout:1.0.2' |
| 185 | + compile 'com.android.support:appcompat-v7:27.0.2' |
| 186 | + testCompile 'junit:junit:4.12' |
| 187 | + compile 'org.tensorflow:tensorflow-android:+' |
| 188 | + compile 'com.wonderkiln:camerakit:0.13.1' |
| 189 | +} |
0 commit comments