曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
Flutter

First Look at Flutter! A Brief Introduction to the Framework and Building a Signed Release APK

Hello! Long time no see. By my count it's been more than a month since I last updated the blog. I just finished a project recently, so I took some time to organize what I've learned and write a blog post. About Flutter I started using Flutter after the Spring Festival. I had actually wanted to learn Flutter for a long time—after all, tech from Google is never too bad—but unfortunately I never had the time or a need to build an app. After getting my hands on Flutter this time, it felt like discovering a new continent. So developing apps can be this convenient? It really overturned my previous understanding. Hot reload is just too good

曦远 (DealiAxy)约 13 分钟
目录4 个章节

Hello! Long time no see. By my count it's been more than a month since I last updated the blog. I just finished a project recently, so I took some time to organize what I've learned and write a blog post.

About Flutter

I started using Flutter after the Spring Festival. I had actually wanted to learn Flutter for a long time—after all, tech from Google is never too bad—but unfortunately I never had the time or a need to build an app. After getting my hands on Flutter this time, it felt like discovering a new continent. So developing apps can be this convenient? It really overturned my previous understanding. Hot reload is just too good, right? Changes show up immediately; you don't need to recompile and reinstall like when developing native Android at all. If it had been like this from the start, how much life would have been saved~ When I first got started, I was just a tiny bit unused to it, because Flutter uses reactive programming, unlike the MVC we're super familiar with, so I was a bit confused at first. But as long as you follow the official tutorials and write a few small demos yourself, you can basically get started. This reactive programming is a lot like React (I haven't used it myself anyway; the frontend gurus say it's similar). As for the Dart language, how should I put it—it feels like a hybrid of Java/JavaScript. Supposedly it was originally meant to be developed to replace JS.... a lot of the syntax is really similar to JS, for example single-threaded + async/await operations, and yet it's a strongly typed language...... Anyway, as for language features, I'm not that familiar yet. It feels alright to write, but nothing particularly dazzling~

Getting to the Point

That was a bit about Flutter. Now let's get to the main topic of this article: how to build a signed APK. If you develop with Android Studio, the built-in APK publishing feature is a bit problematic—it seems you can't generate it through the IDE, so we'll use the official method and do it with the Flutter command.

Modify AndroidManifest information First, since we're compiling an Android app, AndroidManifest.xml definitely needs to be modified—things like permissions, app name, app icon, go ahead and modify those yourself; this article won't go into that.

Configure the signing file This signing file is something everyone doing Android development already has. If you don't have one, generate one with keytool.

keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

Parameter explanation:

-genkey      在用户主目录中创建一个key.jks文件
-v           显示密钥库中的证书详细信息
-alias       产生别名
-keyalg      指定密钥的算法  
-keystore    指定密钥库的名称(产生的各类信息将不在.jks文件中
-validity    指定创建的证书有效期多少天
-keysize     指定密钥长度

Configure key.properties In the <app dir>/android/ directory, create a key.properties file <app dir> represents the project root directory, same below.

Contents as follows:

storePassword=keystore密码
keyPassword=key密码
keyAlias=密钥别名
storeFile=密钥路径

Configure Gradle To compile an Android project, Gradle is indispensable! Gradle file path <app dir>/android/app/build.gradle

Find android {, and configure the key.properties information above this line:

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

Continue down, find buildTypes {, and configure signingConfigs above it

signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

Modify buildTypes

buildTypes {
        release {
           signingConfig signingConfigs.release
        }
    }

If all of the above was completed correctly, you can start building the signed APK. Open a terminal in the app project directory and enter the Flutter build command:

flutter build apk

After the build finishes, it will show the APK path. You can choose to install with adb, or just use flutter install to install~

About


Learn more on my WeChat Official Account:DealiAxy Every post was in my blog:blog.deali.cn

Welcome to Discuss

For questions, please leave a message on the WeChat official account backend. I'll reply to every message~

_EOF_

First Look at Flutter! A Brief Introduction to the Framework and Building a Signed Release APK

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…