uniapp原生APP本地打包成功的步骤

开发环境 | uni小程序SDK

准备工作

dcloud开发者中心
登录dcloud开发者中心后台 -> 我的应用->创建应用

在dcloud开发者中心后台创建一个新的应用


我的应用

3.在我的应用->证书管理->创建证书
这个证书是云打包需要用到的


通过cmd命令生成证书 命令如下
keytool -genkey -alias testApp -keyalg RSA -keysize 2048 -validity 36500 -keystore appDemo.keystore
命令说明

别名->testApp
keystore文件-> appDemo.keystore







注意事项
此处生成的appDemo.keystore是离线打包需要用到的

查看appDemo.keystore的相关详细信息
例如我们需要的别名、以及SHA1这两个信息


可获取MD5签名的JDK版本分享

【详见】可获取MD5签名的JDK版本 分享 - DCloud问答

解压后 在bin目录下 ./keytool.exe ************



在我的应用->证书管理->离线打包Key管理


注意事项->等下会用到Android包名以及App Key

Android包名
Android证书签名SHA1
App Key

如何生成证书 ->参考链接

cmd命令生成证书综合

这一条可以忽略 第4步有
注意事项
前提安装java环境最好是java11 这个单独的记录如何配置javac环境吧

	keytool -genkey -alias testApp -keyalg RSA -keysize 2048 -validity 36500 -keystore appDemo.keystore
    // 说明 testApp是证书的别名    appDemo.keystore 是证书文件
    
    keytool -list -v -keystore appDemo.keystore
    // 查看appDemo.keystore相关信息
uniapp 配置manifest.json


uniapp->发行->原生App-本地打包(L)->生成本地打包App资源(R)





Android Studio 创建空应用


注意事项
Package name 需要和dcloud创建的Android包名保持一致
Language 需要选择Java选择其他的无法运行成功


project -> 创建assets文件

创建完assets 需要创建以下两个文件

apps
data


将HBuilder-Integrate-AS\simpleDemo\src\main\assets\data下的文件复制到刚刚创建的data中
simpleDemo\src\main\assets\data文件


assets文件下的data


修改原始的dcloud_control.xml文件 替换其中的appid

将HBuilder-Integrate-AS\simpleDemo\libs下的文件复制到\testIT\app\libs文件下
注意事项
上面的文件路径都是我电脑这边的文件路径,同学们在测试安装本地包的时候需要将对应的文件路径调整一下




将本地打包的文件复制到apps文件下




修改后的AndroidManifest.xml
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <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.MyApplication"
        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>
修改后的app ->build.gradle

 
plugins {
    id 'com.android.application'
}

android {
    namespace 'com.test.loan.india'
    compileSdk 32

    defaultConfig {
        applicationId "com.test.loan.india"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ndk {abiFilters 'arm64-v8a', 'x86_64','armeabi-v7a','x86'}
    }
    signingConfigs {
        config {
            keyAlias 'testdemo'
            keyPassword 'testdemo'
            storeFile file('testdemo.jks')
            storePassword 'testdemo'
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.config
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            signingConfig signingConfigs.config
            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:*~"
    }
    buildToolsVersion '32.0.0'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "com.alibaba:fastjson:1.1.46.android"
    implementation 'com.squareup.okhttp3:okhttp:3.12.12'
    implementation 'com.squareup.okio:okio:1.15.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    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'
    implementation 'androidx.webkit:webkit:1.3.0'

}
修改gradle.properties

 
android.useAndroidX=true
android.enableJetifier=true
android.bundle.enableUncompressedNativeLibs = false //打包aab需要

离线基座

android——离线打包制作自定义基座 - DCloud问答

<?xml version="1.0" ?>
<hbuilder  debug="true" syncDebug="true">
    <apps>
        <app appid="你的appid" appver=""/>
    </apps>
</hbuilder>

如果提示 “同步资源失败,未得到同步资源的授权,请停止运行后重新运行,并注意手机上的授权提示” .
尝试添加
implementation 'com.squareup.okhttp3:okhttp:3.12.12'
implementation 'com.squareup.okio:okio:1.15.0'

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐