Advertisement
Guest User

Untitled

a guest
Apr 7th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.33 KB | None | 0 0
  1. project.buildDir = 'gradleBuild'
  2. getProject().setBuildDir('gradleBuild')
  3. buildscript {
  4. repositories {
  5. jcenter()
  6. google()
  7. maven {
  8. url 'https://google.bintray.com/tensorflow'
  9. }
  10. }
  11.  
  12. dependencies {
  13. classpath 'com.android.tools.build:gradle:3.1.0'
  14. classpath 'org.apache.httpcomponents:httpclient:4.5.4'
  15.  
  16. }
  17. }
  18.  
  19. allprojects {
  20. repositories {
  21. jcenter()
  22. google()
  23. maven {
  24. url 'https://google.bintray.com/tensorflow'
  25. }
  26. }
  27.  
  28. }
  29.  
  30. // set to 'bazel', 'cmake', 'makefile', 'none'
  31. def nativeBuildSystem = 'cmake'
  32.  
  33. // Controls output directory in APK and CPU type for Bazel builds.
  34. // NOTE: Does not affect the Makefile build target API (yet), which currently
  35. // assumes armeabi-v7a. If building with make, changing this will require
  36. // editing the Makefile as well.
  37. // The CMake build has only been tested with armeabi-v7a; others may not work.
  38. def cpuType = 'arm64-v8a'
  39.  
  40. // Output directory in the local directory for packaging into the APK.
  41. def nativeOutDir = 'libs/' + cpuType
  42.  
  43. // Default to building with Bazel and override with make if requested.
  44. def nativeBuildRule = 'buildNativeBazel'
  45. def demoLibPath = '../../../bazel-bin/tensorflow/examples/android/libtensorflow_demo.so'
  46. def inferenceLibPath = '../../../bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so'
  47.  
  48. // Override for Makefile builds.
  49. if (nativeBuildSystem == 'makefile') {
  50. nativeBuildRule = 'buildNativeMake'
  51. demoLibPath = '../../../tensorflow/contrib/makefile/gen/lib/android_' + cpuType + '/libtensorflow_demo.so'
  52. inferenceLibPath = '../../../tensorflow/contrib/makefile/gen/lib/android_' + cpuType + '/libtensorflow_inference.so'
  53. }
  54.  
  55. // If building with Bazel, this is the location of the bazel binary.
  56. // NOTE: Bazel does not yet support building for Android on Windows,
  57. // so in this case the Makefile build must be used as described above.
  58. def bazelLocation = '/usr/bin/bazel-real'
  59.  
  60. // import DownloadModels task
  61. project.ext.ASSET_DIR = projectDir.toString() + '/assets'
  62. project.ext.TMP_DIR = project.buildDir.toString() + '/downloads'
  63.  
  64. apply plugin: 'com.android.application'
  65.  
  66. android {
  67. compileSdkVersion 27
  68. buildToolsVersion '27.0.3'
  69.  
  70. if (nativeBuildSystem == 'cmake') {
  71. defaultConfig {
  72. applicationId = 'org.tensorflow.demo'
  73. minSdkVersion 26
  74. targetSdkVersion 27
  75. multiDexEnabled true
  76.  
  77. ndk {
  78. abiFilters "${cpuType}"
  79. }
  80. externalNativeBuild {
  81. cmake {
  82. arguments '-DANDROID_TOOLCHAIN=gcc', '-DANDROID_STL=gnustl_static'
  83. }
  84. }
  85. }
  86. externalNativeBuild {
  87. cmake {
  88. path './jni/CMakeLists.txt'
  89. }
  90. }
  91. //deeplearning4J on Android
  92. packagingOptions {
  93. exclude 'META-INF/DEPENDENCIES'
  94. exclude 'META-INF/DEPENDENCIES.txt'
  95. exclude 'META-INF/LICENSE'
  96. exclude 'META-INF/LICENSE.txt'
  97. exclude 'META-INF/license.txt'
  98. exclude 'META-INF/NOTICE'
  99. exclude 'META-INF/NOTICE.txt'
  100. exclude 'META-INF/notice.txt'
  101. exclude 'META-INF/INDEX.LIST'
  102. }
  103. }
  104.  
  105. lintOptions {
  106. abortOnError false
  107. }
  108.  
  109. dexOptions {
  110. javaMaxHeapSize "2048M"
  111.  
  112. }
  113. sourceSets {
  114. main {
  115. if (nativeBuildSystem == 'bazel' || nativeBuildSystem == 'makefile') {
  116. // TensorFlow Java API sources.
  117. java {
  118. srcDir '../../java/src/main/java'
  119. exclude '**/examples/**'
  120. }
  121.  
  122. // Android TensorFlow wrappers, etc.
  123. java {
  124. srcDir '../../contrib/android/java'
  125. }
  126.  
  127. }
  128.  
  129. // Android demo app sources.
  130. java {
  131. srcDir 'src'
  132. }
  133.  
  134. manifest.srcFile 'AndroidManifest.xml'
  135. resources.srcDirs = ['src']
  136. aidl.srcDirs = ['src']
  137. renderscript.srcDirs = ['src']
  138. res.srcDirs = ['res']
  139. assets.srcDirs = [project.ext.ASSET_DIR]
  140. jniLibs.srcDirs = ['libs']
  141. }
  142.  
  143. debug.setRoot('build-types/debug')
  144. release.setRoot('build-types/release')
  145. }
  146. compileOptions {
  147. sourceCompatibility JavaVersion.VERSION_1_8
  148. targetCompatibility JavaVersion.VERSION_1_8
  149. }
  150. }
  151.  
  152. task buildNativeBazel(type: Exec) {
  153. workingDir '../../..'
  154. commandLine bazelLocation, 'build', '-c', 'opt', \
  155. 'tensorflow/examples/android:tensorflow_native_libs', \
  156. '--crosstool_top=//external:android/crosstool', \
  157. '--cpu=' + cpuType, \
  158. '--host_crosstool_top=@bazel_tools//tools/cpp:toolchain'
  159. }
  160.  
  161. task buildNativeMake(type: Exec) {
  162. environment "NDK_ROOT", android.ndkDirectory
  163. // Tip: install ccache and uncomment the following to speed up
  164. // builds significantly.
  165. environment "CC_PREFIX", 'ccache'
  166. workingDir '../../..'
  167. commandLine 'tensorflow/contrib/makefile/build_all_android.sh', \
  168. '-s', \
  169. 'tensorflow/contrib/makefile/sub_makefiles/android/Makefile.in', \
  170. '-t', \
  171. 'libtensorflow_inference.so libtensorflow_demo.so all' \
  172. , '-a', cpuType \
  173. // , '-T' // Uncomment to skip protobuf and speed up subsequent builds.
  174. }
  175.  
  176.  
  177. task copyNativeLibs(type: Copy) {
  178. from demoLibPath
  179. from inferenceLibPath
  180. into nativeOutDir
  181. duplicatesStrategy = 'include'
  182. dependsOn nativeBuildRule
  183. fileMode 0644
  184. }
  185.  
  186. tasks.whenTaskAdded { task ->
  187. if (nativeBuildSystem == 'bazel' || nativeBuildSystem == 'makefile') {
  188. if (task.name == 'assembleDebug') {
  189. task.dependsOn 'copyNativeLibs'
  190. }
  191. if (task.name == 'assembleRelease') {
  192. task.dependsOn 'copyNativeLibs'
  193. }
  194. }
  195. }
  196.  
  197. // Download default models; if you wish to use your own models then
  198. // place them in the "assets" directory and comment out this line.
  199. //apply from: "download-models.gradle"
  200. configurations {
  201. // compile {
  202. compile.exclude module: 'jcip-annotations'
  203. compile.exclude module: 'jsr305'
  204. // transitive = false
  205.  
  206. // }
  207. }
  208. dependencies {
  209. implementation 'com.google.code.findbugs:annotations:3.0.1', {
  210. // Need to exclude these, or build is broken by:
  211. // com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull
  212. // exclude module: 'jcip-annotations'
  213. // exclude module: 'jsr305'
  214. }
  215. implementation 'org.projectlombok:lombok:1.16.16'
  216. annotationProcessor "org.projectlombok:lombok:1.16.16"
  217. implementation 'org.deeplearning4j:deeplearning4j-core:0.9.1'
  218. implementation 'org.nd4j:nd4j-native:0.9.1'
  219. implementation 'org.nd4j:nd4j-native:0.7.2:android-x86'
  220. if (nativeBuildSystem == 'cmake' || nativeBuildSystem == 'none') {
  221. implementation 'org.tensorflow:tensorflow-android:+'
  222.  
  223. }
  224. implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  225. implementation 'com.android.support:support-v4:27.1.0'
  226. implementation 'com.android.support:support-v13:27.1.0'
  227. implementation 'com.android.support:cardview-v7:27.1.0'
  228. implementation 'com.android.support:appcompat-v7:27.1.0'
  229. //For Splitting the video into images.
  230. implementation 'nl.bravobit:android-ffmpeg:1.1.2'
  231. //For Dependency Injection
  232. implementation 'com.google.dagger:dagger:2.12'
  233. annotationProcessor 'com.google.dagger:dagger-compiler:2.12'
  234. //For ViewBinding
  235. implementation 'com.jakewharton:butterknife:8.8.1'
  236. annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
  237. //rest interactions
  238. implementation 'com.squareup.retrofit2:retrofit:2.4.0'
  239. //JSON Parsing
  240. implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
  241. implementation 'com.google.code.gson:gson:2.8.2'
  242. //http logging
  243. implementation 'com.squareup.okhttp3:logging-interceptor:3.4.2'
  244. //For Deleting all videos in a directory
  245. implementation 'commons-io:commons-io:2.6'
  246. //TODO Somehow get deeplearn4j to work in this build file
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement