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”重启模拟器解决模拟器的一些问题