HBuilder X 本地打包资源 打包成 安卓 apk

1、使用 Android Studio 创建一个 工程

HBuilder X 本地打包资源 打包成 安卓 apk
createApplition1.png
HBuilder X 本地打包资源 打包成 安卓 apk
createApplition2.png
HBuilder X 本地打包资源 打包成 安卓 apk
createApplition3.png

2、删除 原生工程中 JAVA 目录下系统默认创建的源代码

HBuilder X 本地打包资源 打包成 安卓 apk
deleteCode.png

3、复制SDK->libs->lib.5plus.base-release.aar文件到原生工程工程的app->libs目录下

HBuilder X 本地打包资源 打包成 安卓 apk
C1CD7CCB-9830-4db7-814A-613E15B87EB9.png
HBuilder X 本地打包资源 打包成 安卓 apk
copyJarPackage.png

4、打开工程的build.gradle文件

  • 4.1 添加aar文件引用到dependenciesr如下代码

 

compile(name: 'lib.5plus.base-release', ext: 'aar')
  • 4.2 添加aar文件搜索路径添到gradle文件,与dependencies同级, 代码如下

 

flatDir{
            dirs 'libs'
        }

build.gradle 文件

 

apply plugin: 'com.android.application'

android {
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.rh.test"
        minSdkVersion 16
//        targetSdkVersion 26
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
// 添加 的代码
repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'lib.5plus.base-release', ext: 'aar')    // 添加的代码  
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    // 注释掉 这三个 测试 的 包
    //testImplementation 'junit:junit:4.12'
    //androidTestImplementation 'com.android.support.test:runner:1.0.2'
    //androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

HBuilder X 本地打包资源 打包成 安卓 apk
B96523E9-0377-4c76-B889-86D88303E545.png
  • 4.3 修改工程的 targetSdkVersion 为21
HBuilder X 本地打包资源 打包成 安卓 apk
ee95ad142db4c9323e792fd42fff04e1.png
  • 4.4 multiDexEnabled 设置成 false (我这里 创建的工程 默认为 false)
HBuilder X 本地打包资源 打包成 安卓 apk
3067AD98-F60F-4ab4-B571-BE0045468E11.png

5、打开工程的Androidmanifest.xml文件,复制以下内容替换该文件中原有application节点下的内容

 

<application
    android:name="io.dcloud.application.DCloudApplication"
    android:allowClearUserData="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    >
    <activity
        android:name="io.dcloud.PandoraEntry"
        android:configChanges="orientation|keyboardHidden|keyboard|navigation"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:hardwareAccelerated="true"
        android:theme="@style/TranslucentTheme"
        android:screenOrientation="user"
        android:windowSoftInputMode="adjustResize" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

替换后的 Androidmanifest.xml 文件

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rh.test">

    <!--<application-->
        <!--android:allowBackup="true"-->
        <!--android:icon="@mipmap/ic_launcher"-->
        <!--android:label="@string/app_name"-->
        <!--android:roundIcon="@mipmap/ic_launcher_round"-->
        <!--android:supportsRtl="true"-->
        <!--android:theme="@style/AppTheme">-->
        <!--<activity android:name=".MainActivity">-->
            <!--<intent-filter>-->
                <!--<action android:name="android.intent.action.MAIN" />-->

                <!--<category android:name="android.intent.category.LAUNCHER" />-->
            <!--</intent-filter>-->
        <!--</activity>-->
    <!--</application>-->
    <application
        android:name="io.dcloud.application.DCloudApplication"
        android:allowClearUserData="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:largeHeap="true"
        >
        <activity
            android:name="io.dcloud.PandoraEntry"
            android:configChanges="orientation|keyboardHidden|keyboard|navigation"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:hardwareAccelerated="true"
            android:theme="@style/TranslucentTheme"
            android:screenOrientation="user"
            android:windowSoftInputMode="adjustResize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

6 在app->src->res->drable目录下放应用的图标文件文件命名为 icon.png

HBuilder X 本地打包资源 打包成 安卓 apk
c509a94c23fd573340e0ad1a8a30d78a.png
HBuilder X 本地打包资源 打包成 安卓 apk
845291BA-064B-4e3e-8220-50B6385B63A9.png

7、 复制SDK->assets->data目录和目录下的文件到工程的src->main->assets目录下,新创建的工程默认没有assets目录,可在与java同级目录下创建assets目录

HBuilder X 本地打包资源 打包成 安卓 apk
7B3CA942-A8FD-4193-AD61-42BA00CE1790.png
HBuilder X 本地打包资源 打包成 安卓 apk
B49E8D9A-D4CC-48cc-AB7F-2B147F8CFFED.png

8、 Assets目录下创建apps目录,复制应用资源到apps目录下。 注意: 应用资源的路径为[appid]->www, appid为应用资源manifest.json文件中id节点的值

HBuilder X 本地打包资源 打包成 安卓 apk
59BA30E0-CD82-4e9a-8BE7-530C1C7AA300.png
  • 8.2 将生成的打包资源 拷贝到 工程的 assets/apps 目录下
HBuilder X 本地打包资源 打包成 安卓 apk
D433E987-7397-463b-95E8-A22530177E6D.png

9、 修改assets->data->dcloud_control.xml文件的apps->app->appid属性的值改为当前应用manifest.json文件id节点的值

来源: HBuilder X 本地打包资源 打包成 安卓 apk - 简书

weinxin
我的微信
一个码农、工程狮、集能量和智慧于一身的、DIY高手、小伙伴er很多的、80后奶爸。
Igor
  • 版权声明: 发表于 2019-03-0516:24:13
  • 转载注明:http://blog.tsingmac.com/prolions/software/android/1678/
Vue使用JsBridge与APP交互 Web服务器

Vue使用JsBridge与APP交互

现在在做的项目是 hybrid 开发,H5 页面会嵌入到 IOS 客户端 app 中,于是就涉及到了 H5 与 IOS 交互的问题。在这里记录一下项目中用到的交互方式,重点介绍 WebViewJava...
树莓派玩家必装的几个Android手机APP 物联网+传感器

树莓派玩家必装的几个Android手机APP

  树莓派之家为各位玩家朋友搜集了以下几个手机APP,有了这些软件,在你把玩树莓派的过程中,会起到如虎添翼的效果。 树莓派之家为各位玩家朋友搜集了以下几个手机APP,有了这些软件,在你把玩树莓派的过程...
Android 环境变量设置 Android

Android 环境变量设置

设置Android环境变量 。 AndroidStudio开发需要设置以下全局的环境变量: ANDROID_HOME: C:\Users\bellesun\AppData\Local\Android\...
Android OpenGL入门 OpenGL

Android OpenGL入门

如今VR这么火,感觉有必要先把OpenGL学好,为以后转VR奠定一些基础。一年前,接触过Android的OpenGL,当时是实现了在Android上显示标准的3D文件(STL格式)。现在打算整理一下O...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: