美文网首页
移植 android studio app 到 android.

移植 android studio app 到 android.

作者: xuefeng_apple | 来源:发表于2020-04-01 18:15 被阅读0次

    1, Android studio
    首先第一步应该是app 在studio 完成,依赖的库,也可以通过studio自动下载,在studio 也可以使用签名,进行release 版本发布,调试
    2, Android.mk
    在android stuido 终究是不方便的,如果做系统, apk release 然后才能anroid版本release ,如果apk 进行mm build ,在build 系统的时候就进行build release 方便

    因此在做到系统里面之前,可以写Android.mk , 依赖现有的Android studio 路径,文件的存放位置,进行build,这样也可以进行android studio build, 做到了兼容。

    3, Studio 到mk
    Android studio version:3.5.3, jdk 1.8, 下图标红位置,是添加文件

    图片.png

    gradle:app/build.gradle, 依赖的库

    dependencies {
       implementation fileTree(dir: 'libs', include: ['*.jar'])
    
       implementation 'androidx.appcompat:appcompat:1.1.0'
       implementation 'com.android.support:support-v13:28.0.0'
       implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
       implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
       implementation 'com.google.protobuf:protobuf-java:3.6.1'
    
       testImplementation 'junit:junit:4.12'
       androidTestImplementation 'androidx.test.ext:junit:1.1.1'
       androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    }
    

    由于系统中使用第三方库,因此需要在Android Studio 中查找对应的jar 包


    图片.png

    其他jar 类似地方找,org.eclipse.paho.client.mqttv3-1.2.0-source.jar : 这种命名的是source 文件,不是import 需要的jar 包。

    下面看mk 文件:

    LOCAL_PATH := $(call my-dir)
    
    # Java ai.test library
    # =======================================================
    include $(CLEAR_VARS)
    LOCAL_MODULE := ai.test
    LOCAL_MODULE_TAGS := optional
    LOCAL_STATIC_JAVA_LIBRARIES :=com.google.protobuf
    LOCAL_SRC_FILES := $(call all-java-files-under, app/build/generated/source/proto/release/java/ai/test)
    LOCAL_JAVA_LANGUAGE_VERSION := 1.8
    include $(BUILD_STATIC_JAVA_LIBRARY)
    
    # Java ai.boxinfo library
    # =======================================================
    include $(CLEAR_VARS)
    LOCAL_MODULE := ai.boxinfo
    LOCAL_MODULE_TAGS := optional
    LOCAL_STATIC_JAVA_LIBRARIES :=com.google.protobuf
    LOCAL_SRC_FILES := $(call all-java-files-under, app/build/generated/source/proto/release/java/ai/boxinfo)
    LOCAL_JAVA_LANGUAGE_VERSION := 1.8
    include $(BUILD_STATIC_JAVA_LIBRARY)
    
    # Java ai.boxcrash library
    # =======================================================
    include $(CLEAR_VARS)
    LOCAL_MODULE := ai.boxcrash
    LOCAL_MODULE_TAGS := optional
    LOCAL_STATIC_JAVA_LIBRARIES :=com.google.protobuf
    LOCAL_SRC_FILES := $(call all-java-files-under, app/build/generated/source/proto/release/java/ai/boxcrash)
    LOCAL_JAVA_LANGUAGE_VERSION := 1.8
    include $(BUILD_STATIC_JAVA_LIBRARY)
    
    # apk build
    # =======================================================
    include $(CLEAR_VARS)
    #eng, user, userdebug. optional build all version
    LOCAL_MODULE_TAGS   := optional
    LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java)
    LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml
    LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/app/src/main/res
    
    #apk setting
    LOCAL_PACKAGE_NAME := MqttApp
    LOCAL_CERTIFICATE := platform
    LOCAL_DEX_PREOPT := false
    
    # add static java jar
    LOCAL_STATIC_JAVA_LIBRARIES :=android-common  guava
    LOCAL_STATIC_JAVA_LIBRARIES +=org.eclipse.paho.client.mqttv3
    LOCAL_STATIC_JAVA_LIBRARIES +=org.eclipse.paho.android.service
    LOCAL_STATIC_JAVA_LIBRARIES +=android-support-v13
    LOCAL_STATIC_JAVA_LIBRARIES +=androidx.annotation
    LOCAL_STATIC_JAVA_LIBRARIES +=ai.test
    LOCAL_STATIC_JAVA_LIBRARIES +=ai.boxinfo
    LOCAL_STATIC_JAVA_LIBRARIES +=ai.boxcrash
    
    include $(BUILD_PACKAGE)
    include $(CLEAR_VARS)
    include $(call all-makefiles-under,$(LOCAL_PATH))
    
    # prebuild jar form third partment
    #######################################
    include $(CLEAR_VARS)
    #before ':' is jar alias, after ':'is jar file path
    LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := androidx.annotation:libs/annotation-1.1.0.jar
    LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += org.eclipse.paho.client.mqttv3:libs/org.eclipse.paho.client.mqttv3-1.2.0.jar
    LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += org.eclipse.paho.android.service:libs/org.eclipse.paho.android.service-1.1.1.jar
    LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += com.google.protobuf:libs/protobuf-java-3.6.1.jar
    include $(BUILD_MULTI_PREBUILT)
    #######################################
    

    有上面的apk 可以看出,引用第三方库位置:libs/ 下面,引用方法:


    图片.png

    备注:上面的写法中,引用的ai.test jar 包, 是Android.mk build 出的。 在build ai.test 中 引用了地方三库, 引用方法:LOCAL_STATIC_JAVA_LIBRARIES :=com.google.protobuf

    Reference:
    https://blog.csdn.net/yuanhcn/article/details/52239558
    https://blog.csdn.net/dzy_mails/article/details/51909112
    https://www.xuebuyuan.com/2038942.html

    相关文章

      网友评论

          本文标题:移植 android studio app 到 android.

          本文链接:https://www.haomeiwen.com/subject/tcnauhtx.html