microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
java/build-android.gradle
168lines · modecode
| 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 publishDir = System.properties['publishDir'] |
| 7 | def minSdkVer = System.properties['minSdkVer'] ?: 24 |
| 8 | def targetSdkVer = System.properties['targetSdkVer'] ?: 32 |
| 9 | def ndkVer = System.properties['ndkVer'] ?: "25.1.8937393" |
| 10 | |
| 11 | // Since Android requires a higher numbers indicating more recent versions |
| 12 | // This function assume ORT version number will be in format of A.B.C such as 1.7.0 |
| 13 | // We generate version code A[0{0,1}]B[0{0,1}]C, |
| 14 | // for example '1.7.0' -> 10700, '1.6.15' -> 10615 |
| 15 | def getVersionCode(String version) { |
| 16 | String[] code = version.split('\\-') |
| 17 | String[] codes = code[0].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.group = "com.microsoft.onnxruntime" |
| 26 | project.version = rootProject.file('../version.txt').text.trim() |
| 27 | |
| 28 | def mavenArtifactId = project.name + '-android' |
| 29 | |
| 30 | buildscript { |
| 31 | repositories { |
| 32 | google() |
| 33 | mavenCentral() |
| 34 | } |
| 35 | dependencies { |
| 36 | classpath 'com.android.tools.build:gradle:7.3.0' |
| 37 | |
| 38 | // NOTE: Do not place your application dependencies here; they belong |
| 39 | // in the individual module build.gradle files |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | allprojects { |
| 44 | repositories { |
| 45 | google() |
| 46 | mavenCentral() |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | android { |
| 51 | compileSdkVersion 32 |
| 52 | ndkVersion ndkVer |
| 53 | defaultConfig { |
| 54 | minSdkVersion minSdkVer |
| 55 | targetSdkVersion targetSdkVer |
| 56 | versionCode = getVersionCode(project.version) |
| 57 | versionName = project.version |
| 58 | |
| 59 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 60 | } |
| 61 | |
| 62 | android { |
| 63 | lintOptions { |
| 64 | abortOnError false |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | buildTypes { |
| 69 | release { |
| 70 | minifyEnabled false |
| 71 | debuggable false |
| 72 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | compileOptions { |
| 77 | sourceCompatibility = JavaVersion.VERSION_1_8 |
| 78 | targetCompatibility = JavaVersion.VERSION_1_8 |
| 79 | } |
| 80 | |
| 81 | sourceSets { |
| 82 | main { |
| 83 | jniLibs.srcDirs = [jniLibsDir] |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | publishing { |
| 88 | singleVariant("release") { |
| 89 | withSourcesJar() |
| 90 | withJavadocJar() |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | } |
| 95 | |
| 96 | task sourcesJar(type: Jar) { |
| 97 | archiveClassifier = "sources" |
| 98 | from android.sourceSets.main.java.srcDirs |
| 99 | } |
| 100 | |
| 101 | task javadoc(type: Javadoc) { |
| 102 | source = android.sourceSets.main.java.srcDirs |
| 103 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) |
| 104 | } |
| 105 | |
| 106 | task javadocJar(type: Jar, dependsOn: javadoc) { |
| 107 | archiveClassifier = 'javadoc' |
| 108 | from javadoc.destinationDir |
| 109 | } |
| 110 | |
| 111 | artifacts { |
| 112 | archives javadocJar |
| 113 | archives sourcesJar |
| 114 | } |
| 115 | |
| 116 | dependencies { |
| 117 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' |
| 118 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' |
| 119 | testImplementation 'com.google.protobuf:protobuf-java:3.21.7' |
| 120 | } |
| 121 | |
| 122 | project.afterEvaluate { |
| 123 | publishing { |
| 124 | publications { |
| 125 | maven(MavenPublication) { |
| 126 | from components.release |
| 127 | groupId = project.group |
| 128 | artifactId = mavenArtifactId |
| 129 | version = project.version |
| 130 | |
| 131 | pom { |
| 132 | name = 'onnxruntime-extensions' |
| 133 | description = 'ONNXRuntime-Extensions is a library for Android for pre- and post-processing.' |
| 134 | url = 'https://microsoft.github.io/onnxruntime/' |
| 135 | licenses { |
| 136 | license { |
| 137 | name = 'MIT License' |
| 138 | url = 'https://opensource.org/licenses/MIT' |
| 139 | } |
| 140 | } |
| 141 | organization { |
| 142 | name = 'Microsoft' |
| 143 | url = 'http://www.microsoft.com' |
| 144 | } |
| 145 | scm { |
| 146 | connection = 'scm:git:git://github.com:microsoft/onnxruntime-extensions.git' |
| 147 | developerConnection = 'scm:git:ssh://github.com/microsoft/onnxruntime-extensions.git' |
| 148 | url = 'http://github.com/microsoft/onnxruntime-extensions' |
| 149 | } |
| 150 | developers { |
| 151 | developer { |
| 152 | id = 'onnxruntime' |
| 153 | name = 'ONNX Runtime' |
| 154 | email = 'onnxruntime@microsoft.com' |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | //publish to filesystem repo |
| 162 | repositories { |
| 163 | maven { |
| 164 | url "$publishDir" |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |