onnxruntime

Форк
0
/
build-android.gradle 
204 строки · 5.7 Кб
1
apply plugin: 'com.android.library'
2
apply plugin: 'maven-publish'
3

4
def jniLibsDir = System.properties['jniLibsDir']
5
def buildDir = System.properties['buildDir']
6
def headersDir = System.properties['headersDir']
7
def publishDir = System.properties['publishDir']
8
def minSdkVer = System.properties['minSdkVer']
9
def targetSdkVer = System.properties['targetSdkVer']
10
boolean enableTrainingApis = (System.properties['ENABLE_TRAINING_APIS'] ?: "0") == "1"
11

12
// Since Android requires a higher numbers indicating more recent versions
13
// This function assume ORT version number will be in formart of A.B.C such as 1.7.0
14
// We generate version code A[0{0,1}]B[0{0,1}]C,
15
// for example '1.7.0' -> 10700, '1.6.15' -> 10615
16
def getVersionCode(String version){
17
	String[] codes = version.split('\\.');
18
	// This will have problem if we have 3 digit [sub]version number, such as 1.7.199
19
	// but it is highly unlikely to happen
20
	String versionCodeStr = String.format("%d%02d%02d", codes[0] as int, codes[1] as int, codes[2] as int);
21
	return versionCodeStr as int;
22
}
23

24
project.buildDir = buildDir
25
project.version = rootProject.file('../VERSION_NUMBER').text.trim()
26
project.group = "com.microsoft.onnxruntime"
27

28
def tmpArtifactId = enableTrainingApis ? project.name + "-training" : project.name
29
def mavenArtifactId = tmpArtifactId + '-android'
30
def defaultDescription = 'ONNX Runtime is a performance-focused inference engine for ONNX (Open Neural Network ' +
31
	'Exchange) models. This package contains the Android (aar) build of ONNX Runtime. It includes support for all ' +
32
	'types and operators, for ONNX format models. All standard ONNX models can be executed with this package.'
33
def trainingDescription = 'The onnxruntime-training android package is designed to efficiently train and infer a ' +
34
	'wide range of ONNX models on edge devices, such as mobile phones, tablets, and other portable devices with ' +
35
	'a focus on minimizing resource usage and maximizing accuracy.' +
36
	'See https://github.com/microsoft/onnxruntime-training-examples/tree/master/on_device_training for more details.'
37

38
buildscript {
39
	repositories {
40
		google()
41
		mavenCentral()
42
	}
43
	dependencies {
44
		classpath 'com.android.tools.build:gradle:7.4.2'
45

46
		// NOTE: Do not place your application dependencies here; they belong
47
		// in the individual module build.gradle files
48
	}
49
}
50

51
allprojects {
52
	repositories {
53
		google()
54
		mavenCentral()
55
	}
56
}
57

58
android {
59
	compileSdkVersion 32
60

61
	defaultConfig {
62
		minSdkVersion minSdkVer
63
		targetSdkVersion targetSdkVer
64
		versionCode = getVersionCode(project.version)
65
		versionName = project.version
66

67
		testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
68
	}
69

70
	android {
71
		lintOptions {
72
			abortOnError false
73
		}
74
	}
75

76
	buildTypes {
77
		release {
78
			minifyEnabled false
79
			debuggable false
80
			proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
81
		}
82
	}
83

84
	compileOptions {
85
		sourceCompatibility = JavaVersion.VERSION_1_8
86
		targetCompatibility = JavaVersion.VERSION_1_8
87
	}
88

89
	sourceSets {
90
		main {
91
			jniLibs.srcDirs = [jniLibsDir]
92
			java {
93
				srcDirs = ['src/main/java', 'src/main/android']
94
			}
95
		}
96
	}
97

98
	namespace 'ai.onnxruntime'
99
}
100

101
task sourcesJar(type: Jar) {
102
	archiveClassifier = "sources"
103
	from android.sourceSets.main.java.srcDirs
104
}
105

106
task javadoc(type: Javadoc) {
107
	source = android.sourceSets.main.java.srcDirs
108
	classpath += project.files(android.getBootClasspath())
109
}
110

111
task javadocJar(type: Jar, dependsOn: javadoc) {
112
	archiveClassifier = 'javadoc'
113
	from javadoc.destinationDir
114
}
115

116
artifacts {
117
	archives javadocJar
118
	archives sourcesJar
119
}
120

121
dependencies {
122
	testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
123
	testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
124
	testImplementation 'com.google.protobuf:protobuf-java:3.21.7'
125
}
126

127
publishing {
128
	publications {
129
		maven(MavenPublication) {
130
			groupId = project.group
131
			artifactId = mavenArtifactId
132
			version = project.version
133

134
			// Three artifacts, the `aar`, the sources and the javadoc
135
			artifact("$buildDir/outputs/aar/${project.name}-release.aar")
136
			artifact javadocJar
137
			artifact sourcesJar
138

139
			pom {
140
				name = enableTrainingApis ? 'onnxruntime-training' : 'onnx-runtime'
141
				description = enableTrainingApis ? trainingDescription : defaultDescription
142
				url = 'https://microsoft.github.io/onnxruntime/'
143
				licenses {
144
					license {
145
						name = 'MIT License'
146
						url = 'https://opensource.org/licenses/MIT'
147
					}
148
				}
149
				organization {
150
					name = 'Microsoft'
151
					url = 'http://www.microsoft.com'
152
				}
153
				scm {
154
					connection = 'scm:git:git://github.com:microsoft/onnxruntime.git'
155
					developerConnection = 'scm:git:ssh://github.com/microsoft/onnxruntime.git'
156
					url = 'http://github.com/microsoft/onnxruntime'
157
				}
158
				developers {
159
					developer {
160
						id = 'onnxruntime'
161
						name = 'ONNX Runtime'
162
						email = 'onnxruntime@microsoft.com'
163
					}
164
				}
165
			}
166
		}
167
	}
168

169
	//publish to filesystem repo
170
	repositories{
171
		maven {
172
			url "$publishDir"
173
		}
174
	}
175
}
176

177
// Add ORT C and C++ API headers to the AAR package, after task bundleDebugAar or bundleReleaseAar
178
// Such that developers using ORT native API can extract libraries and headers from AAR package without building ORT
179
tasks.whenTaskAdded { task ->
180
	if (task.name.startsWith("bundle") && task.name.endsWith("Aar")) {
181
		doLast {
182
			addFolderToAar("addHeadersTo" + task.name, task.archivePath, headersDir, 'headers')
183
		}
184
	}
185
}
186

187
def addFolderToAar(taskName, aarPath, folderPath, folderPathInAar) {
188
	def tmpDir = file("${buildDir}/${taskName}")
189
	tmpDir.mkdir()
190
	def tmpDirFolder = file("${tmpDir.path}/${folderPathInAar}")
191
	tmpDirFolder.mkdir()
192
	copy {
193
		from zipTree(aarPath)
194
		into tmpDir
195
	}
196
	copy {
197
		from fileTree(folderPath)
198
		into tmpDirFolder
199
	}
200
	ant.zip(destfile: aarPath) {
201
		fileset(dir: tmpDir.path)
202
	}
203
	delete tmpDir
204
}
205

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.