-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle
139 lines (118 loc) · 4.34 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// path to checkout of https://github.com/tensorflow/tensorflow
def tensorflowRepo = '/data/androidStudioProjects/tensorflow/'
// Default to building with Bazel and override with make if requested.
def nativeBuildRule = 'buildNativeBazel'
def inferenceLibPath = tensorflowRepo + '/bazel-bin/tensorflow/contrib/android/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 = 'bazel'
project.buildDir = 'gradleBuild'
getProject().setBuildDir('gradleBuild')
// import DownloadModels task
project.ext.ASSET_DIR = projectDir.toString() + '/assets'
project.ext.TMP_DIR = project.buildDir.toString() + '/downloads'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
lintOptions {
abortOnError false
}
def mainDir = "src/main"
sourceSets {
main {
// TensorFlow Java API sources.
java {
srcDir tensorflowRepo + 'tensorflow/java/src/main/java'
exclude '**/examples/**'
}
// Android TensorFlow wrappers, etc.
java {
srcDir tensorflowRepo + 'tensorflow/contrib/android/java'
}
java.srcDir 'src/main/java'
manifest.srcFile 'AndroidManifest.xml'
resources.srcDirs = ['src/main/res']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = [project.ext.ASSET_DIR]
jniLibs.srcDirs = ['libs']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
applicationId "com.vackosar.youtubereader"
minSdkVersion 11
targetSdkVersion 11
versionCode 1
versionName "1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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:25.3.1'
compile 'commons-lang:commons-lang:2.3'
testCompile 'junit:junit:4.12'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
}
task buildNativeBazel() {
doLast {
buildNativeBazelForCpu('x86', tensorflowRepo, bazelLocation, inferenceLibPath)
buildNativeBazelForCpu('armeabi', tensorflowRepo, bazelLocation, inferenceLibPath)
buildNativeBazelForCpu('armeabi-v7a', tensorflowRepo, bazelLocation, inferenceLibPath)
}
}
def buildNativeBazelForCpu(String cpu, tensorflowRepo, bazelLocation, inferenceLibPath) {
def libDir = System.getProperty("user.dir") + "/libs"
if (!file(libDir + "/" + cpu + "/libtensorflow_inference.so").exists()) {
exec {
workingDir tensorflowRepo
commandLine bazelLocation, 'build', '-c', 'opt', 'tensorflow/examples/android:tensorflow_native_libs', '--crosstool_top=//external:android/crosstool', '--cpu=' + cpu, '--host_crosstool_top=@bazel_tools//tools/cpp:toolchain'
}
exec {
workingDir tensorflowRepo
commandLine "mkdir", "-p", libDir + "/" + cpu
}
exec {
workingDir tensorflowRepo
commandLine 'cp', "-f", inferenceLibPath, libDir + "/" + cpu
}
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebug') {
task.dependsOn nativeBuildRule
}
if (task.name == 'assembleRelease') {
task.dependsOn nativeBuildRule
}
}
// 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"