uniapp-android离线打包

官方文档https://nativesupport.dcloud.net.cn/AppDocs/usesdk/androidhttps://nativesupport.dcloud.net.cn/AppDocs/usesdk/android一、环境准备

1.下载android studio Download Android Studio and SDK tools  |  Android Developers

2.App离线SDK下载

       百度网盘 请输入提取码,提取码: 7rfu

3.安装android studio

 

 安装目录可以按照自己的想法选择目标磁盘

 

 等待安装完成

 

安装完成后点finish且运行android studio 

启动IDE后会提示没有SDK,这一步可以忽略点击calcel

 如果自己没有准备SDK可以按IDE默认提示安装

 二、工程配置

1.找到官方下载的SDK目录按照官方找到里边的四个jar包复制到新工程libs中

 2.配置build.gradle文件(注意是app中的build.gradle)

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.testapp"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    aaptOptions {
        additionalParameters '--auto-add-overlay'
        ignoreAssetsPattern "!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation fileTree(include: ['*.aar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.facebook.fresco:fresco:2.5.0'
    implementation "com.facebook.fresco:animated-gif:2.5.0"
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'com.alibaba:fastjson:1.1.46.android'

}

配置完gladle文件记得点击右上角Sync Now按钮进行配置同步 

3.配置Appkey  生成安卓平台签名证书

 Android平台签名证书(.keystore)生成指南 - DCloud问答

证书生成后记得配置gradle 

将生成的sha1密钥在Dcloud开发中心去配置离线打包key(包名,证书别名,证书的SHA1,还有你的uniapp的AppID)

4.配置打包签名

在3中我们已经生成了证书,证书可以是keystore格式或者jks格式,可以命令生成也可以android studio生成。参考Android 签名打包简介_www121104115的博客-CSDN博客前提:开发工具:Android studio 3.0.1 Android 打包apk是上线的必经流程 下面简单介绍其中一种打包方式:分为两种情况1,没有签名文件(即 .jks文件) 2,已经有(.jks)文件1.已经有(.jks)情况下点击如下图所示 key store path : .jks 所在的文件夹 key store password : 你的密码(密钥库安全...https://blog.csdn.net/www121104115/article/details/79405665

Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)

解决方法是gradle.properties中添加以下配置,选择AndroidX作为支持库(记得sync now)

android.useAndroidX=true
android.enableJetifier=true

5.生成j证书文件后运行如果报这样的错说明缺少build.gradle配置 

运行期间如果出现appkey is not configured or configured incorrect报错 ,那么检查一下app下的build.gradle文件是否配置了signingConfigs模块

都配置好了如果报错没有消除请检查appid+应用包名+签名sha1三者必须与申请填写的信息一致才可以的

5.配置AndroidManifest.xml文件

在application节点中添加meta-data节点和activity节点,以下代码(记得删除原有的activity节点

注意点:配置完后项目没跑起来,参照这篇文章每个activity节点加了个android:exported = "true"uniapp 发行 原生APP本地打包_坐等夕阳落time的博客-CSDN博客_uniapp本地打包

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

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TestApp"
        tools:targetApi="31">
        <meta-data
            android:name="dcloud_appkey"
            android:value="替换为自己申请的Appkey" />
        <activity
            android:exported = "true"
            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>
        <activity
            android:exported = "true"
            android:name="io.dcloud.PandoraEntryActivity"
            android:launchMode="singleTask"
            android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale|keyboard|smallestScreenSize|screenLayout|screenSize"
            android:hardwareAccelerated="true"
            android:permission="com.miui.securitycenter.permission.AppPermissionsEditor"
            android:screenOrientation="user"
            android:theme="@style/DCloudTheme"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <action android:name="android.intent.action.VIEW" />
                <data android:scheme="h56131bcf" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 5.配置打包签名

在3中我们已经生成了签名和签名文件,那么现在需要在app build.gradle配置打包所需的签名

 首先点击build下的signed bundle-》next

 可以创建一个新的签名(create new)或者选择我们之前生成的签名文件choose exising

 6.配置appid和appkey

1)在uniapp中发行-》生成本地app资源

 

红框标记的就是你打包的文件位置 

2)在android studio中创建assets文件夹 app->src->main文件夹下创建

在快捷文件列表中直接选assets即可,不要直接在文件管理器里创建

 

 在assets中新建apps和data文件夹

apps中存的就是uniapp打包的本地app资源

data中放上边下载的sdk里的assets里的data里的三个文件复制粘贴到我们新建的data文件夹

 在dcloud_control.xml文件中修改自己的uniapp AppID

如果没有模拟器和真机那么需要去配置一个模拟器

 

 

 一直next,如果没有systemSDKdown一个就行。

 finish

 模拟器就出来了,可以运行了。

 在真机模拟运行时如果手机的usb验证应用无法开启添加以下代码解决(一般是vivo和oppo)

在gradle.properties文件中添加android.injected.testOnly=false

注:作者为小白一名,此文是本人在测试原生打包时实际过程,以及参考其他大佬文章。

另:此文章非商业用途,如有侵权请联系作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值