2024年HarmonyOS鸿蒙最新鸿蒙开发初体验(Android开发必看)(2),2024年最新社招面试的问题

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!


img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

}
});
directionalLayout.addComponent(button);

// 步骤5 将布局作为根布局添加到视图树中
super.setUIContent(directionalLayout);
}

首页的布局如下,通过Java代码创建

@Override
public void onStart(Intent intent) {
super.onStart(intent);
System.out.println(“onStart”);
LayoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT);
myLayout.setLayoutConfig(config);
ShapeElement element = new ShapeElement();
element.setRgbColor(new RgbColor(255, 255, 255));
myLayout.setBackground(element);

Text text = new Text(this);
text.setLayoutConfig(config);
text.setText(“CT Jackie”);
text.setTextColor(new Color(0xFF000000));
text.setTextSize(50);
text.setTextAlignment(TextAlignment.CENTER);
myLayout.addComponent(text);
super.setUIContent(myLayout);
}

效果如下:

2.生命周期

下面再来看看主界面的生命周期,实现了ILifecycle接口,生命周期状态一共有七种

public static enum Event {
UNDEFINED,
ON_START,
ON_INACTIVE,
ON_ACTIVE,
ON_BACKGROUND,
ON_FOREGROUND,
ON_STOP;
private Event() {
}
}

界面启动时调用onStart()和onActive()

2020-09-13 21:42:10.266 25547-25547[表情] I/System.out: onStart
2020-09-13 21:42:10.284 25547-25547[表情] I/System.out: onActive

点击返回键时调用

2020-09-13 21:42:35.847 25547-25547/com.example.helloworld I/System.out: onInactive
2020-09-13 21:42:35.917 25547-25547/com.example.helloworld I/System.out: onBackground
2020-09-13 21:42:35.920 25547-25547/com.example.helloworld I/System.out: onStop

至于UNDEFINED和ON_FOREGROUND暂时还不了解。

3.Gradle任务(Task)

甚至连gradle的Task都非常类似,打包命令是assembleDebug/Release

Task :entry:preBuild
Task :entry:compileDebugNativeWithCmake
Task :entry:collectDebugDependencies
Task :entry:mergeDebugResources
Task :entry:mergeDebugProfile
Task :entry:compileDebugResources
Task :entry:compileDebugIdl
Task :entry:compileDebugRFile
Task :entry:processDebugJavaResource
Task :entry:compileDebugJavaWithJavac
Task :entry:mergeDebugJavaResource
Task :entry:generateDebugClassesJar
Task :entry:mergeDebugProjectDex
Task :entry:generateDebugShell
Task :entry:processDebugShellManifest
Task :entry:compileDebugShellResources
Task :entry:linkDebugShellResources
Task :entry:compileDebugShellJavaWithJavac
Task :entry:mergeDebugShellDex
Task :entry:packageDebugShell
Task :entry:packageDebugSimplifyShell
Task :entry:validateDebugSigning
Task :entry:signDebugShell
Task :entry:packageDebugHap
Task :entry:signDebugHap
Task :entry:assembleDebug

4.配置文件

配置文件是一个命名为config.json的文件,配置应用的一些信息

{
“app”: {
“bundleName”: “com.example.helloworld”,
“vendor”: “example”,
“version”: {
“code”: 1,
“name”: “1.0”
},
“apiVersion”: {
“compatible”: 3,
“target”: 3
}
},
“deviceConfig”: {
“default”: {

}
},
“module”: {
“package”: “com.example.helloworld”,
“name”: “.HelloWorld”,
“reqCapabilities”: [
“video_support”
],
“deviceType”: [
“wearable”
],
“distro”: {
“deliveryWithInstall”: true,
“moduleName”: “entry”,
“moduleType”: “entry”
},
“abilities”: [
{
“skills”: [
{
“entities”: [
“entity.system.home”
],
“actions”: [
“action.system.home”
]
}
],
“orientation”: “landscape”,
“formEnabled”: false,
“name”: “com.example.helloworld.MainAbility”,
“icon”: “ m e d i a : i c o n " , " d e s c r i p t i o n " : " media:icon", "description": " media:icon","description":"string:mainability_description”,
“label”: “HelloWorld”,
“type”: “page”,
“launchType”: “standard”
}
]
}
}

仔细看这个文件会越来越觉得这就是AndroidManifest.xml的json翻译版。

反编译角度看鸿蒙

既然看起来这么像安卓,我看来看看它编译后的产物是什么,是不是也能像android一样反编译得到dex文件?

编译后得到的是一个xxx.hap文件

修改它的后缀名为.zip,解压后可以看到里面有熟悉的assets,dex,apk文件等,把这个apk文件安装后发现并不能使用。

下面我们先反编译这个classes.dex文件第一个dex反编译后出现错误

~/Desktop/fanbianyi/dex2jar-2.0 » sh d2j-dex2jar.sh classes3.dex
dex2jar classes3.dex -> ./classes3-dex2jar.jar
com.googlecode.d2j.DexException: not support version.
at com.googlecode.d2j.reader.DexFileReader.(DexFileReader.java:151)
at com.googlecode.d2j.reader.DexFileReader.(DexFileReader.java:211)
at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:104)
at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:288)
at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:32)

原因是我们的工具版本太低了,解决方案在这,升级版本后反编译成功后为classes3-dex2jar.jar,打开可以看到

这里多了个ResourceTable文件,就是我们的资源id表。这里的dex文件包含的是我们开发的代码。

下面我们来反编译apk文件,解压后可以看到,里面是我们熟悉的内容

AndroidManifest.xml文件如下

反编译该dex文件可以看到,MainAbilityShellActivity最终是继承了AbilityShellActivity

ShellHelloWorld其实一个Application

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!


img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

存中…(img-rD8HhvY6-1715641159421)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值