pytorch / android-demo-app

PyTorch android examples of usage in applications
1.47k stars 606 forks source link

Getting started with Pytorch mobile #45

Open guraaf opened 4 years ago

guraaf commented 4 years ago

I tried to build Pytorch demo app for the first time. I am new to gradlew etc. having only used CMake and Make etc for C/C++ builds in past. I tried the following steps but installDebug is not found. ./gradlew tasks definitely doesn't have any installDebug tasks.

Is the documentation old or am I missing a step or two below? I do have Android SDK and NDK installed as far as I can tell.

$ git clone https://github.com/pytorch/android-demo-app.git
$ cd android-demo-app
$ cd HelloWorldApp
$ python trace_model.py
$ ./gradlew installDebug
FAILURE: Build failed with an exception.

* What went wrong:
Task 'installDebug' not found in root project 'HelloWorldApp'.

* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
$ ./gradlew tasks

> Task :tasks

------------------------------------------------------------
Tasks runnable from root project
------------------------------------------------------------

Android tasks
-------------
sourceSets - Prints out all the source sets defined in this project.

Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
clean - Deletes the build directory.
cleanBuildCache - Deletes the build cache directory.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'HelloWorldApp'.
components - Displays the components produced by root project 'HelloWorldApp'. [incubating]
dependencies - Displays all dependencies declared in root project 'HelloWorldApp'.
dependencyInsight - Displays the insight into a specific dependency in root project 'HelloWorldApp'.
dependentComponents - Displays the dependent components of components in root project 'HelloWorldApp'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'HelloWorldApp'. [incubating]
projects - Displays the sub-projects of root project 'HelloWorldApp'.
properties - Displays the properties of root project 'HelloWorldApp'.
tasks - Displays the tasks runnable from root project 'HelloWorldApp' (some of the displayed tasks may belong to subprojects).

Install tasks
-------------
uninstallAll - Uninstall all applications.

Verification tasks
------------------
check - Runs all checks.
connectedCheck - Runs all device checks on currently connected devices.
deviceCheck - Runs all device checks using Device Providers and Test Servers.

To see all tasks and more detail, run gradlew tasks --all

To see more detail about a task, run gradlew help --task <task>

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
dreiss commented 4 years ago

I think I've seen this happen when the Android SDK isn't found. I don't remember the exact solution, though. Maybe run export ANDROID_HOME=/path/to/android/sdk? Or maybe try opening it with Android Studio to see if it creates a local.properties with the correct path?

guraaf commented 4 years ago

Thanks @dreiss. This fixed the issue. One more quick question (hopefully last one?) - which and where does one get an emulator? gradlew installDebug now complains of no device being connected.

Does the Pytorch Mobile community have a preferred and suggested device emulator for MacOS or Linux distros?

dreiss commented 4 years ago

The emulator is integrated with Android Studio: https://developer.android.com/studio/run/emulator