Build Android APK

I want to build an android using my own deep learning network. But i change the code in tvm/apps/android_deploy/app/src/main/java/ml/dmlc/tvm/android/demo/MainActivity.java

the code I change as follow:

private static final int MODEL_INPUT_SIZE = 512;

private static final String MODEL_GRAPH_FILE = “file:///android_asset/my_mlp-symbol.json”;
private static final String MODEL_PARAM_FILE = “file:///android_asset/my_mlp-0000.params”;
private static final String MODEL_LABEL_FILE = “file:///android_asset/my_mlp.shortnames.list”;

and the document ‘my_mlp-symbol.json’, ‘my_mlp-0000.params’ and ‘my_mlp.shortnames.list’ are the network structure, parameters, and the label document

I can use gradle to build the APK, but after installation, the APP can’t open.
Who can help me ?
Thank you

I was following this Android TVM Demo tutorial

System:
         ubuntu 18.04
         Gradle 5.0
         LLVM 6.x
         gcc and g++ 6.x
         Apache Maven 3.5.2
         Docker version 18.09.0
         ~Android/Sdk:NDK16.1

But I met some trouble like those:

acui@OFShare:~/tvm/tvm/apps/android_deploy$ gradle clean build
> Task :app:buildJni
/home/acui/tvm/tvm/apps/android_deploy/app/src/main/jnistrong text
Android NDK: WARNING: APP_PLATFORM android-17 is higher than android:minSdkVersion 1 in /home/acui/tvm/tvm/apps/android_deploy/app/src/main/AndroidManifest.xml. NDK binaries will *not* be comptible with devices older than android-17. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.    
make: Entering directory `/home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni'
/home/acui/Android/Sdk/ndk-bundle/build/core/setup-app.mk:81: Android NDK: Application targets deprecated ABI(s): mips64 armeabi mips    
/home/acui/Android/Sdk/ndk-bundle/build/core/setup-app.mk:82: Android NDK: Support for these ABIs will be removed in a future NDK release.    
[arm64-v8a] Compile++      : tvm4j_runtime_packed <= ml_dmlc_tvm_native_c_api.cc
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/ml_dmlc_tvm_native_c_api.cc:8:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/tvm_runtime.h:9:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/c_runtime_api.cc:9:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/tvm/runtime/packed_func.h:18:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/tvm/runtime/module.h:11:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../3rdparty/dmlc-core/include/dmlc/./io.h:445:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../3rdparty/dmlc-core/include/dmlc/./serializer.h:22:
/home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../3rdparty/dmlc-core/include/dmlc/./endian.h:26:6: error: "Unable to determine endianness of your machine; use CMake to compile"
    #error "Unable to determine endianness of your machine; use CMake to compile"
     ^
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/ml_dmlc_tvm_native_c_api.cc:8:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/tvm_runtime.h:9:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/../src/runtime/c_runtime_api.cc:9:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/tvm/runtime/packed_func.h:18:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../include/tvm/runtime/module.h:11:
In file included from /home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../3rdparty/dmlc-core/include/dmlc/./io.h:445:
/home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../3rdparty/dmlc-core/include/dmlc/./serializer.h:85:9: error: use of undeclared identifier 'DMLC_LITTLE_ENDIAN'
    if (DMLC_IO_NO_ENDIAN_SWAP) {
        ^
/home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni/../../../../../../3rdparty/dmlc-core/include/dmlc/./endian.h:32:33: note: expanded from macro 'DMLC_IO_NO_ENDIAN_SWAP'
#define DMLC_IO_NO_ENDIAN_SWAP (DMLC_LITTLE_ENDIAN == DMLC_IO_USE_LITTLE_ENDIAN)
 .......
omitted
 .......
17 errors generated.
make: *** [/home/acui/tvm/tvm/apps/android_deploy/app/src/main/obj/local/arm64-v8a/objs/tvm4j_runtime_packed/ml_dmlc_tvm_native_c_api.o] Error 1
make: Leaving directory `/home/acui/tvm/tvm/apps/android_deploy/app/src/main/jni'

> Task :app:buildJni FAILED

FAILURE: Build failed with an exception.

on above outputs of errors,I noticed " #error “Unable to determine endianness of your machine; use CMake to compile” so I vim this tvm/apps/android_deploy/app/src/main/jni/Application.mk file and changed only one line of this:

APP_CPPFLAGS += -DDMLC_LOG_STACK_TRACE=0 -DDMLC_CMAKE_LITTLE_ENDIAN=1 -DTVM4J_ANDROID=1 -std=c++11 -Oz -frtti

(-DDMLC_CMAKE_LITTLE_ENDIAN=0 I also tried.It can also compile this project successfully but can’t run the apk on mobile device)


Then I can compile this project and produce apk file successfully.But when I have installed the apk,the app seems work incorrectly.Like this:

The TVM Android Demo shows dialog “prediction running on image…” then break up.

So does ‘the tvm android demo’ have some bug?Can somebody give me some helpful information. Thanks in advance. @FrozenGene @derisavi @Trami

Hi @OFShare I don’t have Android mobile currently, so I can’t reproduce your issue. For the Endian, it should be related with this commit: https://github.com/dmlc/dmlc-core/commit/05754313c5933a62386892a7446912c2bffe57ce For most of Android phones should be little endian, i.e. should be set 1. I think this commit maybe don’t cover Android situation.

It should be some commit break the runtime. Others meet it too. For example on this thread: The demo of android (adroid_deploy) run with crash which says that this PR: https://github.com/dmlc/tvm/pull/1646 break it. So would you mind roll back to try?

@tqchen I think we should care these things. We should keep our tutorials and demos always work correctly, I think it is important for new comers.

If we can automate the APK build flow, we can try to add it to the CI