uni-app offline local packaging (Android) configuration tutorial

development environment

HBuilder X 3.1.18.20210609
Android Studio 4.2.2
JDK 11
gradle 7.1.1
App Offline SDK 3.1.18

Basically all of them are up-to-date, no links are provided, everyone can download them by themselves, basically all major official websites have download links, so you don’t have to worry about accidentally installing the family bucket.

New Construction

Open Android Studioa new blank project

insert image description here

select empty Activityclicknext

insert image description here

  • NameProject name
  • Package name Package name, in a formal environment, the package name should be consistent with the company's engineering java project
  • Save location Save location locally
  • Language must choose Java
  • The Minimum SDK corresponds to the Android version that needs to be adapted. According to your own needs, it is not recommended to choose too high

Fill in and clickFinish
insert image description here

Clicking the progress bar in the lower right corner will pop up a progress details box, first click the small fork to cancel the dependent download

insert image description here

The above is the newly created default configuration. The default dependent source is foreign. Modify the dependent source to a domestic mirror, which is faster, as follows

// Top-level build file where you can add configuration options common to all sub-projects/modules.  

buildscript {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        maven {
            url 'https://maven.aliyun.com/repository/jcenter'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }
        maven {
            url 'https://maven.aliyun.com/repository/jcenter'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

insert image description here

Add uni-appthe required dependencies and other configurations, the above is the default, modified as follows

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.demo"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
    }
    signingConfigs {
        config {
            keyAlias 'test'
            keyPassword '111111'
            storeFile file('test.keystore')
            storePassword '111111'
            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:*~"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
    implementation "com.android.support:support-v4:28.0.0"
    implementation "com.android.support:appcompat-v7:28.0.0"
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.facebook.fresco:fresco:1.13.0'
    implementation "com.facebook.fresco:animated-gif:1.13.0"
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'com.alibaba:fastjson:1.1.46.android'
}

After completing the above operations, you can download the dependent resources, click File > Sync Project with Gradle File, and continue the following preparations while waiting for the dependent download

insert image description here

After the dependency download is completed, the project is managed by gradle, so in the development tool, the directory structure will change, just change the directory structure to project

insert image description here

Delete some initialized things, otherwise the package cannot be successfully packaged, and the selected files can be deleted directly, as shown in the figure below

insert image description here

Add external dependencies. From App离线SDKthe package, find latest > 3.1.18 > [email protected]_20210610 > HBuilder-Integrate-AS > simpleDemo > libs, and copy all the files inside to app > libs

insert image description here

Add resource files required by uni-app
Copy App离线SDKlatest > 3.1.18 > [email protected]_20210610 > HBuilder-Integrate-AS > simpleDemo > src > main > assets directly in the package and put them in app > src > main, and then delete appsall the files under the directory

insert image description here

Open HBuilder X, create a new project, this part will not be introduced in detail, just choose a template, and then generate local resources

insert image description here

Copy the generated resource file to appsthe folder below, as shown below

insert image description here
insert image description here

Modify the configuration, find data > dcloud_control.xml, and modify the appid to the directory name of the generated resource file.

insert image description here

To generate a signing certificate for the Android platform, click Build > Generate Signed Bundle / APK…

insert image description here

Select APK and click Next

insert image description here

select new

insert image description here

Select build directory

insert image description here

Under the app directory of the selected project, the file name is taken by yourself. What I give here is test

insert image description here

The default generated suffix is ​​jks, change the suffix to .keystore

insert image description here

Fill in the information, the password I always take is 111111, the alias is test, click OK after completion

insert image description here

After the information here is echoed, go directly to next

insert image description here

Check them all, then select release, click finish, and the certificate will be generated, under the app directory

insert image description here

Then modify the build.gradle file configuration. If you directly copy the configuration above me, and the certificate generation method is the same as mine, you don’t need to modify anything, otherwise you can modify it according to your own generation method.

insert image description here

Apply for an appkey, log in to the DCloud management background , select your own project, and then click Offline Packaging Key Management, you will see the following page, where you need the Android certificate signature SHA1

insert image description here

View the certificate signature information, click gradle, find this command, double-click to execute it to see the certificate information

insert image description here

Fill in some information about applying for the certificate, and copy the SHA1 value in the above box to the Android certificate signature. The package name is also in build.gradle, and then uncheck if you don’t need ios

insert image description here

Save it when you are done, and the appkey information will be generated.

insert image description here

Go back to the development tool, first delete the things in the red box, and then add the following configuration

insert image description here

The following configuration is the official configuration, just copy it directly

        <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>
        <activity
            android:name="io.dcloud.PandoraEntryActivity"
            android:launchMode="singleTask"
            android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale|keyboard"
            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>
        <!--provider节点必须添加-->
        <provider
            android:name="io.dcloud.common.util.DCloud_FileProvider"
            android:authorities="com.example.uniapp.dc.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/dcloud_file_provider" />
        </provider>

The following configuration is the configuration of appkey

        <meta-data
            android:name="dcloud_appkey"
            android:value="申请的appkey" />

The complete configuration file is as follows

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="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>
        <activity
            android:name="io.dcloud.PandoraEntryActivity"
            android:launchMode="singleTask"
            android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale|keyboard"
            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>
        <!--provider节点必须添加-->
        <provider
            android:name="io.dcloud.common.util.DCloud_FileProvider"
            android:authorities="com.example.uniapp.dc.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/dcloud_file_provider" />
        </provider>

        <meta-data
            android:name="dcloud_appkey"
            android:value="申请的appkey" />
    </application>
</manifest>

The above has completed all the configurations, and then it can be packaged. According to the following operations, it can be packaged

insert image description here

Guess you like

Origin blog.csdn.net/qq_33733799/article/details/118580182