onnxruntime
204 строки · 5.7 Кб
1apply plugin: 'com.android.library'
2apply plugin: 'maven-publish'
3
4def jniLibsDir = System.properties['jniLibsDir']
5def buildDir = System.properties['buildDir']
6def headersDir = System.properties['headersDir']
7def publishDir = System.properties['publishDir']
8def minSdkVer = System.properties['minSdkVer']
9def targetSdkVer = System.properties['targetSdkVer']
10boolean 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
16def getVersionCode(String version){
17String[] 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
20String versionCodeStr = String.format("%d%02d%02d", codes[0] as int, codes[1] as int, codes[2] as int);
21return versionCodeStr as int;
22}
23
24project.buildDir = buildDir
25project.version = rootProject.file('../VERSION_NUMBER').text.trim()
26project.group = "com.microsoft.onnxruntime"
27
28def tmpArtifactId = enableTrainingApis ? project.name + "-training" : project.name
29def mavenArtifactId = tmpArtifactId + '-android'
30def 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.'
33def 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
38buildscript {
39repositories {
40google()
41mavenCentral()
42}
43dependencies {
44classpath '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
51allprojects {
52repositories {
53google()
54mavenCentral()
55}
56}
57
58android {
59compileSdkVersion 32
60
61defaultConfig {
62minSdkVersion minSdkVer
63targetSdkVersion targetSdkVer
64versionCode = getVersionCode(project.version)
65versionName = project.version
66
67testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
68}
69
70android {
71lintOptions {
72abortOnError false
73}
74}
75
76buildTypes {
77release {
78minifyEnabled false
79debuggable false
80proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
81}
82}
83
84compileOptions {
85sourceCompatibility = JavaVersion.VERSION_1_8
86targetCompatibility = JavaVersion.VERSION_1_8
87}
88
89sourceSets {
90main {
91jniLibs.srcDirs = [jniLibsDir]
92java {
93srcDirs = ['src/main/java', 'src/main/android']
94}
95}
96}
97
98namespace 'ai.onnxruntime'
99}
100
101task sourcesJar(type: Jar) {
102archiveClassifier = "sources"
103from android.sourceSets.main.java.srcDirs
104}
105
106task javadoc(type: Javadoc) {
107source = android.sourceSets.main.java.srcDirs
108classpath += project.files(android.getBootClasspath())
109}
110
111task javadocJar(type: Jar, dependsOn: javadoc) {
112archiveClassifier = 'javadoc'
113from javadoc.destinationDir
114}
115
116artifacts {
117archives javadocJar
118archives sourcesJar
119}
120
121dependencies {
122testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
123testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
124testImplementation 'com.google.protobuf:protobuf-java:3.21.7'
125}
126
127publishing {
128publications {
129maven(MavenPublication) {
130groupId = project.group
131artifactId = mavenArtifactId
132version = project.version
133
134// Three artifacts, the `aar`, the sources and the javadoc
135artifact("$buildDir/outputs/aar/${project.name}-release.aar")
136artifact javadocJar
137artifact sourcesJar
138
139pom {
140name = enableTrainingApis ? 'onnxruntime-training' : 'onnx-runtime'
141description = enableTrainingApis ? trainingDescription : defaultDescription
142url = 'https://microsoft.github.io/onnxruntime/'
143licenses {
144license {
145name = 'MIT License'
146url = 'https://opensource.org/licenses/MIT'
147}
148}
149organization {
150name = 'Microsoft'
151url = 'http://www.microsoft.com'
152}
153scm {
154connection = 'scm:git:git://github.com:microsoft/onnxruntime.git'
155developerConnection = 'scm:git:ssh://github.com/microsoft/onnxruntime.git'
156url = 'http://github.com/microsoft/onnxruntime'
157}
158developers {
159developer {
160id = 'onnxruntime'
161name = 'ONNX Runtime'
162email = 'onnxruntime@microsoft.com'
163}
164}
165}
166}
167}
168
169//publish to filesystem repo
170repositories{
171maven {
172url "$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
179tasks.whenTaskAdded { task ->
180if (task.name.startsWith("bundle") && task.name.endsWith("Aar")) {
181doLast {
182addFolderToAar("addHeadersTo" + task.name, task.archivePath, headersDir, 'headers')
183}
184}
185}
186
187def addFolderToAar(taskName, aarPath, folderPath, folderPathInAar) {
188def tmpDir = file("${buildDir}/${taskName}")
189tmpDir.mkdir()
190def tmpDirFolder = file("${tmpDir.path}/${folderPathInAar}")
191tmpDirFolder.mkdir()
192copy {
193from zipTree(aarPath)
194into tmpDir
195}
196copy {
197from fileTree(folderPath)
198into tmpDirFolder
199}
200ant.zip(destfile: aarPath) {
201fileset(dir: tmpDir.path)
202}
203delete tmpDir
204}
205