Skip to content

Commit

Permalink
[android] android gradle project for ops (#2897)
Browse files Browse the repository at this point in the history
* [android] android gradle project for ops

* Change CMakeLists to latest PyTorch

* Use mobilenet_v3 models for detection

Don't need to have two variants of the model anymore, but I'm not removing it for now

* Fix orientation when angle = 0

* [android][test_app] Fix YUV decoding

* Use smaller version of mobilenet model

* Divide inputs by 255 again

* [android] assets mobilenetv3

Co-authored-by: Francisco Massa <fvsmassa@gmail.com>
  • Loading branch information
IvanKobzarev and fmassa authored Feb 4, 2021
1 parent aa26498 commit 6949b89
Show file tree
Hide file tree
Showing 30 changed files with 1,447 additions and 0 deletions.
8 changes: 8 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local.properties
**/*.iml
.gradle
gradlew*
gradle/wrapper
.idea/*
.externalNativeBuild
build
43 changes: 43 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
allprojects {
buildscript {
ext {
minSdkVersion = 21
targetSdkVersion = 28
compileSdkVersion = 28
buildToolsVersion = '28.0.3'

coreVersion = "1.2.0"
extJUnitVersion = "1.1.1"
runnerVersion = "1.2.0"
rulesVersion = "1.2.0"
junitVersion = "4.12"

androidSupportAppCompatV7Version = "28.0.0"
fbjniJavaOnlyVersion = "0.0.3"
soLoaderNativeLoaderVersion = "0.8.0"
}

repositories {
google()
mavenCentral()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:${GRADLE_BINTRAY_PLUGIN_VERSION}"
classpath "com.github.dcendents:android-maven-gradle-plugin:${ANDROID_MAVEN_GRADLE_PLUGIN_VERSION}"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.9.8"
}
}

repositories {
google()
jcenter()
}
}

ext.deps = [
jsr305: 'com.google.code.findbugs:jsr305:3.0.1',
]

28 changes: 28 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ABI_FILTERS=armeabi-v7a,arm64-v8a,x86,x86_64

VERSION_NAME=0.0.1-SNAPSHOT
GROUP=org.pytorch
MAVEN_GROUP=org.pytorch
POM_URL=https://github.com/pytorch/vision/
POM_SCM_URL=https://github.com/pytorch/vision.git
POM_SCM_CONNECTION=scm:git:https://github.com/pytorch/vision
POM_SCM_DEV_CONNECTION=scm:git:git@github.com:pytorch/vision.git
POM_LICENSE_NAME=BSD 3-Clause
POM_LICENSE_URL=https://github.com/pytorch/vision/blob/master/LICENSE
POM_ISSUES_URL=https://github.com/pytorch/vision/issues
POM_LICENSE_DIST=repo
POM_DEVELOPER_ID=pytorch
POM_DEVELOPER_NAME=pytorch
syncWithMavenCentral=true

GRADLE_BINTRAY_PLUGIN_VERSION=1.8.0
GRADLE_VERSIONS_PLUGIN_VERSION=0.15.0
ANDROID_MAVEN_GRADLE_PLUGIN_VERSION=2.1

# Gradle internals
android.useAndroidX=true
android.enableJetifier=true

testAppAllVariantsEnabled=false

org.gradle.jvmargs=-Xmx4096m
38 changes: 38 additions & 0 deletions android/gradle_scripts/android_maven_install.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apply plugin: 'com.github.dcendents.android-maven'

version = VERSION_NAME
group = GROUP
project.archivesBaseName = POM_ARTIFACT_ID

install {
repositories.mavenInstaller {
pom.project {
name POM_NAME
artifactId POM_ARTIFACT_ID
packaging POM_PACKAGING
description POM_DESCRIPTION
url projectUrl

scm {
url scmUrl
connection scmConnection
developerConnection scmDeveloperConnection
}

licenses {
license {
name = POM_LICENSE_NAME
url = POM_LICENSE_URL
distribution = POM_LICENSE_DIST
}
}

developers {
developer {
id developerId
name developerName
}
}
}
}
}
95 changes: 95 additions & 0 deletions android/gradle_scripts/android_tasks.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

import java.nio.file.Files
import java.nio.file.Paths
import java.io.FileOutputStream
import java.util.zip.ZipFile

// Android tasks for Javadoc and sources.jar generation

afterEvaluate { project ->
if (POM_PACKAGING == 'aar') {
task androidJavadoc(type: Javadoc, dependsOn: assembleDebug) {
source += files(android.sourceSets.main.java.srcDirs)
failOnError false
// This task will try to compile *everything* it finds in the above directory and
// will choke on text files it doesn't understand.
exclude '**/BUCK'
exclude '**/*.md'
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}

android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
task "jar${name}"(type: Jar, dependsOn: variant.javaCompileProvider) {
from variant.javaCompileProvider.get().destinationDir
}

androidJavadoc.doFirst {
classpath += files(android.bootClasspath)
classpath += files(variant.javaCompileProvider.get().classpath.files)
// This is generated by `assembleDebug` and holds the JARs generated by the APT.
classpath += fileTree(dir: "$buildDir/intermediates/bundles/debug/", include: '**/*.jar')

// Process AAR dependencies
def aarDependencies = classpath.filter { it.name.endsWith('.aar') }
classpath -= aarDependencies
aarDependencies.each { aar ->
// Extract classes.jar from the AAR dependency, and add it to the javadoc classpath
def outputPath = "$buildDir/tmp/aarJar/${aar.name.replace('.aar', '.jar')}"
classpath += files(outputPath)

// Use a task so the actual extraction only happens before the javadoc task is run
dependsOn task(name: "extract ${aar.name}").doLast {
extractEntry(aar, 'classes.jar', outputPath)
}
}
}
}

artifacts.add('archives', androidJavadocJar)
artifacts.add('archives', androidSourcesJar)
}

if (POM_PACKAGING == 'jar') {
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts.add('archives', javadocJar)
artifacts.add('archives', sourcesJar)
}
}

// Utility method to extract only one entry in a zip file
private def extractEntry(archive, entryPath, outputPath) {
if (!archive.exists()) {
throw new GradleException("archive $archive not found")
}

def zip = new ZipFile(archive)
zip.entries().each {
if (it.name == entryPath) {
def path = Paths.get(outputPath)
if (!Files.exists(path)) {
Files.createDirectories(path.getParent())
Files.copy(zip.getInputStream(it), path)
}
}
}
zip.close()
}
64 changes: 64 additions & 0 deletions android/gradle_scripts/bintray.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apply plugin: 'com.jfrog.bintray'

def getBintrayUsername() {
return project.hasProperty('bintrayUsername') ? property('bintrayUsername') : System.getenv('BINTRAY_USERNAME')
}

def getBintrayApiKey() {
return project.hasProperty('bintrayApiKey') ? property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
}

def getBintrayGpgPassword() {
return project.hasProperty('bintrayGpgPassword') ? property('bintrayGpgPassword') : System.getenv('BINTRAY_GPG_PASSWORD')
}

def getMavenCentralUsername() {
return project.hasProperty('mavenCentralUsername') ? property('mavenCentralUsername') : System.getenv('MAVEN_CENTRAL_USERNAME')
}

def getMavenCentralPassword() {
return project.hasProperty('mavenCentralPassword') ? property('mavenCentralPassword') : System.getenv('MAVEN_CENTRAL_PASSWORD')
}

def shouldSyncWithMavenCentral() {
return project.hasProperty('syncWithMavenCentral') ? property('syncWithMavenCentral').toBoolean() : false
}

def dryRunOnly() {
return project.hasProperty('dryRun') ? property('dryRun').toBoolean() : false
}

bintray {
user = getBintrayUsername()
key = getBintrayApiKey()
override = false
configurations = ['archives']
pkg {
repo = bintrayRepo
userOrg = bintrayUserOrg
name = bintrayName
desc = bintrayDescription
websiteUrl = projectUrl
issueTrackerUrl = issuesUrl
vcsUrl = scmUrl
licenses = [ POM_LICENSE_NAME ]
dryRun = dryRunOnly()
override = false
publish = true
publicDownloadNumbers = true
version {
name = versionName
desc = bintrayDescription
gpg {
sign = true
passphrase = getBintrayGpgPassword()
}
mavenCentralSync {
sync = shouldSyncWithMavenCentral()
user = getMavenCentralUsername()
password = getMavenCentralPassword()
close = '1' // If set to 0, you have to manually click release
}
}
}
}
99 changes: 99 additions & 0 deletions android/gradle_scripts/gradle_maven_push.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
apply plugin: 'signing'

version = VERSION_NAME
group = MAVEN_GROUP

def isReleaseBuild() {
return !VERSION_NAME.contains('SNAPSHOT')
}

def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}

def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}

def getRepositoryUsername() {
return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : ""
}

def getHttpProxyHost() {
return project.properties['systemProp.http.proxyHost']
}

def getHttpProxyPort() {
return project.properties['systemProp.http.proxyPort']
}

def needProxy() {
return (getHttpProxyHost() != null) && (getHttpProxyPort() != null)
}

afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

pom.groupId = MAVEN_GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
if (needProxy()) {
proxy(host: getHttpProxyHost(), port: getHttpProxyPort() as Integer, type: 'http')
}
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
if (needProxy()) {
proxy(host: getHttpProxyHost(), port: getHttpProxyPort() as Integer, type: 'http')
}
}

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENSE_NAME
url POM_LICENSE_URL
distribution POM_LICENSE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}

signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask('uploadArchives') }
sign configurations.archives
}

}
5 changes: 5 additions & 0 deletions android/gradle_scripts/release.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apply from: rootProject.file('gradle_scripts/android_tasks.gradle')

apply from: rootProject.file('gradle_scripts/release_bintray.gradle')

apply from: rootProject.file('gradle_scripts/gradle_maven_push.gradle')
Loading

0 comments on commit 6949b89

Please sign in to comment.