十、Android签名、多项目打包与Gitee


前言

👨‍💻👨‍🌾📝记录学习成果,以便温故而知新

1.签名

(1)生成Key

如下图,菜单“Build”=>“Generate Signed Bundle / APK…”,弹出“Generate Signed Bundle or APK”窗口
在这里插入图片描述在这里插入图片描述选择“APK”,点击“Next”按钮,界面切换成如下图
在这里插入图片描述
点击“Create new…”按钮,弹出如下对话框
在这里插入图片描述输入两组密码与确认密码,点击“OK”,保存证书

(2)打包

如下图,选择打包模块与Key,输入密码
在这里插入图片描述点击“Next”按钮,弹出如下图,选择目标路径与编译变量,点击“Finish”,开始打包,成功后有提示

在这里插入图片描述

2.多项目打包

一个项目分别打包测试版与长期支持版需要如下设置

(1)配置build.gradle

在这里插入图片描述
在这里插入图片描述buildConfigField配置项DB_IP通过Java代码中获取

private final String IP = BuildConfig.DB_IP;

resValue配置项中app_name通过xml获取

android:label="@string/app_name"

如图
在这里插入图片描述resValue配置项中app_name取代的是strings.xml中的设置,两者不能重复,否则报错
在这里插入图片描述

(2)效果

在这里插入图片描述在这里插入图片描述模拟器中运行release貌似会报错,暂无解决方案,有了解决方案再做补充

(3)代码MainActivity、activity_main

package cn.fy.version;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import cn.fy.version.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    private final String IP = BuildConfig.DB_IP;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.txtDbIp.setText(IP);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/txt_db_ip"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="60dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="60dp"
        android:hint="数据库IP"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <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/Theme.AppCode">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
    </application>

</manifest>

(4)包名

配置

// 自定义打包名称
    android.applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "appCode_${variant.productFlavors[0].name}.apk"
        }
    }

编译选项
在这里插入图片描述打包结果,Beta版与LTS版在这里插入图片描述生成的文件分别是appCode_Beta.apk与appCode_LTS.apk

在这里插入图片描述在这里插入图片描述

3.Gitee

(1)安装插件

在这里插入图片描述

(2)上传代码

分享到Gitee
在这里插入图片描述不需要先在Gitee上建项目,如果建了会报已存在
上传前需要登录,上传成功后集成开发环境出现“Git”菜单
在这里插入图片描述
Gitee地址https://gitee.com/dycq/AppCode

4.Android Studio

(1)两个有用的配置

HTTP Proxy,加快sdk的下载

http://mirrors.neusoft.edu.cn

如图
在这里插入图片描述在这里插入图片描述
settings.gradle配置Maven加快依赖包下载,如图
在这里插入图片描述

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven {url 'https://developer.huawei.com/repo/'}
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {url 'https://developer.huawei.com/repo/'}
    }
}
rootProject.name = "AppCode"
include ':app'
include ':layout'
include ':navigation'
include ':dialog'
include ':audio'
include ':photo'
include ':location'
include ':sqlite'
include ':nfc'
include ':version'

感谢华为的库

(2)两个有用的操作

清除缓存
菜单“File”=>“Invalidate Caches…”,弹出“Invalidate Caches”窗口, 清除缓存,可以解决一些编译问题
在这里插入图片描述在这里插入图片描述Cold Boot
“Device Manager”中的“Cold Boot Now”重启模拟器解决模拟器的一些问题
在这里插入图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值