分类 linux 下的文章

写在最前,安装完cmdline-tools 一定要同意license 才能正常使用

   yes | ${sdk}/cmdline-tools/latest/bin/sdkmanager --licenses

首先进入android studio 官网

在国内的话,访问cn域名可以明显方便很多

https://developer.android.google.cn/develop?hl=zh-cn

并找到命令行工具的部分

https://developer.android.google.cn/studio?hl=zh-cn 下滑找到 仅限命令行工具

可以看到 Windows, macOS, Linux的选项,点击其中一个并且确认勾选进行下载

下载连接如:

https://googledownloads.cn/android/repository/commandlinetools-linux-13114758_latest.zip

下载完毕后,解压至 ~/cmdline_tools

这个包就是SDK,只是命名不同,重新修改命名即可


一个能够用于安卓编译的SDK目录应该如下:

(base) casdon@mac ~ % ls /Users/casdon/Library/Android/sdk 
build-tools cmdline-tools   fonts       ndk     platforms   sources
cmake       emulator    licenses    platform-tools  skins       system-images

上面的下载包只能是 cmdline-tools 所以官网的相关内容也是有问题的:

sdkmanager
sdkmanager 是一个命令行工具,您可以用它来查看、安装、更新和卸载 Android SDK 的软件包。如果使用 Android Studio,则无需使用此工具,而可以从 IDE 管理 SDK 软件包。

sdkmanager 工具在 Android SDK 命令行工具软件包中提供。如需使用 SDK 管理器安装某个版本的命令行工具,请按以下步骤操作:

从 Android Studio 页面下载最新的命令行工具软件包,然后提取该软件包。
将解压缩的 cmdline-tools 目录移至您选择的新目录,例如 android_sdk。这个新目录就是您的 Android SDK 目录。
在解压缩的 cmdline-tools 目录中,创建一个名为 latest 的子目录。
将原始 cmdline-tools 目录内容(包括 lib 目录、bin 目录、NOTICE.txt 文件和 source.properties 文件)移动到新创建的 latest 目录中。现在,您就可以从这个位置使用命令行工具了。

使用sdkmanager来安装对应的sdk

首先进入

cd ~/
mkdir -p Android/sdk/cmdline-tools/latest

将上一下载的 cmdline-tools 放置到 Android目录下

mv ~/cmdline_tools/* ~/Android/sdk/cmdline-tools/latest

随后使用 cmdline-tools中的 sdkmanager来安装完整的sdk,特别是编译C/CPP JNI的库,一定要安装NDK

我们以以下几个版本为例进行安装

  • ndk;27.3.13750724
  • platform 21,24.. 31,32,33,34
  • build-tools 35.0.0
  • system-images android-27 android-35
# 使用 --list 方式查看可供下载的内容
cd ~/Android/sdk/cmdline-tools
./latest/bin/sdkmanager --sdk_root=/home/dev/Android/sdk --list

[=======================================] 100% Computing updates...             

Available Packages:
  Path                                                                            | Version           | Description                                                           
  -------                                                                         | -------           | -------                                                               
  add-ons;addon-google_apis-google-15                                             | 3                 | Google APIs                                                           
  add-ons;addon-google_apis-google-16                                             | 4                 | Google APIs                                                           
  add-ons;addon-google_apis-google-17                                             | 4                 | Google APIs                                                           
  add-ons;addon-google_apis-google-18                                             | 4                 | Google APIs                                                           
  add-ons;addon-google_apis-google-19                                             | 20                | Google APIs                                                           
  add-ons;addon-google_apis-google-21                                             | 1                 | Google APIs                                                           
  add-ons;addon-google_apis-google-22                                             | 1                 | Google APIs                                                           
  add-ons;addon-google_apis-google-23                                             | 1                 | Google APIs                                                           
  add-ons;addon-google_apis-google-24                                             | 1                 | Google APIs                                                           
  build-tools;19.1.0                                                              | 19.1.0            | Android SDK Build-Tools 19.1                                          
  build-tools;20.0.0                                                              | 20.0.0            | Android SDK Build-Tools 20                                            
  build-tools;21.1.2                                                              | 21.1.2            | Android SDK Build-Tools 21.1.2                                        
  build-tools;22.0.1                                                              | 22.0.1            | Android SDK Build-Tools 22.0.1                                        
  build-tools;23.0.1                                                              | 23.0.1            | Android SDK Build-Tools 23.0.1                                        
  build-tools;23.0.2                                                              | 23.0.2            | Android SDK Build-Tools 23.0.2                                        
  build-tools;23.0.3                                                              | 23.0.3            | Android SDK Build-Tools 23.0.3                                        
  build-tools;24.0.0                                                              | 24.0.0            | Android SDK Build-Tools 24                                            
  build-tools;24.0.1                                                              | 24.0.1            | Android SDK Build-Tools 24.0.1                                        
  build-tools;24.0.2                                                              | 24.0.2            | Android SDK Build-Tools 24.0.2                                        
  build-tools;24.0.3                                                              | 24.0.3            | Android SDK Build-Tools 24.0.3                                        
  build-tools;25.0.0                                                              | 25.0.0            | Android SDK Build-Tools 25                                            
  build-tools;25.0.1                                                              | 25.0.1            | Android SDK Build-Tools 25.0.1                                        
  build-tools;25.0.2                                                              | 25.0.2            | Android SDK Build-Tools 25.0.2                                        
  build-tools;25.0.3                                                              | 25.0.3            | Android SDK Build-Tools 25.0.3                                        
  build-tools;26.0.0                                                              | 26.0.0            | Android SDK Build-Tools 26                                            
  build-tools;26.0.1                                                              | 26.0.1            | Android SDK Build-Tools 26.0.1                                        
  build-tools;26.0
  ....

再根据上述版本号内容,选择对应工具链和版本进行安装,注意 需要使用双引号

cd ~/Android/sdk
./cmdline-tools/latest/bin/sdkmanager --install "ndk;27.3.13750724"
./cmdline-tools/latest/bin/sdkmanager "platforms;android-27"
./cmdline-tools/latest/bin/sdkmanager "platforms;android-34"
./cmdline-tools/latest/bin/sdkmanager "build-tools;35.0.1"

随后只需要将 路径输出到环境变量即可

export ANDROID_SYSROOT=~/Android/sdk

也可以把对应的输出放到 .bashrc中

JDK

不要忘了安装JDK

## default
sudo apt install openjdk-default -y

# 17
sudo apt install openjdk-17-jdk -y

Sometimes, we need to run a script to modify saveral files at once.

We can use xargs on shell tube.

ls | xargs echo 

As the command before, xargs run echo and use the result from ls.

this example shows how to use xargs modify all index.html that change *.js to *.js?ver=xxx

verStr="1.0.0"

# set version for  .css .js files
find -name "index.html" | xargs -i cp {} {}.bak 

find -name "index.html" | xargs sed -i 's@\.js.*\"@.js?ver='${verStr}'\"@g'

# reset files
# find -name "index.html" | xargs -i mv {}.bak {} 

在进行嵌入式开发的时候,文件传输是比较麻烦的 在调试过程中,最方便的方式是使用nfs进行文件目录共享 记录一下在设备和ubuntu之间共享的方法

在ubuntu上开启nfs共享

1. 安装和开启nfs-server服务

sudo apt install nfs-kernel-server

2. 配置共享文件目录

此时可以创建一个新目录 或者使用 开发目录来进行共享,这里以 /home/my/dev 为例

sudo vi /etc/exports

添加

/home/my/dev  192.168.*(rw,sync,no_root_squash)

如果出现Protocol not supported 可以在 /etc/default/nfs-kernel-server末尾添加

PRCNFSDORTS="--nfs-version 2,3,4 --debug --syslog"

3. 刷新服务

sudo systemctl restart nfs-server.service

4. 检查状态

sudo exportfs -v

lv_draw_sw_img_decoded

img_decoded 是用于解码图片并且将图片绘制到指定buffer区域。

LV_ATTRIBUTE_FAST_MEM 
void lv_draw_sw_img_decoded
(
struct _lv_draw_ctx_t * draw_ctx,
const lv_draw_img_dsc_t * draw_dsc,
const lv_area_t * coords, 
const uint8_t * src_buf, 
lv_img_cf_t cf
)

/**
    struct _lv_draw_ctx_t * draw_ctx        // 绘制上下文
    const lv_draw_img_dsc_t * draw_dsc      // 图像素材绘制描述
    const lv_area_t * coords                // 绘制区(图像在output buffer上的绝对定位)
    const uint8_t * src_buf                  // 图像buffer
    lv_img_cf_t cf                          // 图像色彩格式
**/

绘制上下文中,与当前绘制图像相关的属性:

typedef struct _lv_draw_ctx_t  {
    /**
     *  Pointer to a buffer to draw into
     */
    void * buf;

    /**
     * The position and size of `buf` (absolute coordinates)
     */
    lv_area_t * buf_area;

    /**
     * The current clip area with absolute coordinates, always the same or smaller than `buf_area`
     */
    const lv_area_t * clip_area;

} lv_draw_ctx_t;

与图像本身的绘制效果相关的:

typedef struct {

    int16_t angle;
    uint16_t zoom;
    lv_point_t pivot;

    lv_color_t recolor;
    lv_opa_t recolor_opa;

    lv_opa_t opa;
    lv_blend_mode_t blend_mode : 4;

    int32_t frame_id;
    uint8_t antialias       : 1;
} lv_draw_img_dsc_t;

lvgl doc flex

lv_obj_set_layout(obj, LV_LAYOUT_FLEX)

The possible values for flex_flow are:

LV_FLEX_FLOW_ROW: Place the children in a row without wrapping
不换行的ROW

LV_FLEX_FLOW_COLUMN: Place the children in a column without wrapping

LV_FLEX_FLOW_ROW_WRAP: Place the children in a row with wrapping

LV_FLEX_FLOW_COLUMN_WRAP: Place the children in a column with wrapping

LV_FLEX_FLOW_ROW_REVERSE: Place the children in a row without wrapping but in reversed order

LV_FLEX_FLOW_COLUMN_REVERSE: Place the children in a column without wrapping but in reversed order

LV_FLEX_FLOW_ROW_WRAP_REVERSE: Place the children in a row with wrapping but in reversed order

LV_FLEX_FLOW_COLUMN_WRAP_REVERSE: Place the children in a column with wrapping but in reversed order



The possible values are:

LV_FLEX_ALIGN_START: means left on a horizontally and top vertically. (default)

LV_FLEX_ALIGN_END: means right on a horizontally and bottom vertically

LV_FLEX_ALIGN_CENTER: simply center

LV_FLEX_ALIGN_SPACE_EVENLY: items are distributed so that the spacing between any two items (and the space to the edges) is equal. Does not apply to track_cross_place.

LV_FLEX_ALIGN_SPACE_AROUND: items are evenly distributed in the track with equal space around them. Note that visually the spaces aren't equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies. Not applies to track_cross_place.

LV_FLEX_ALIGN_SPACE_BETWEEN: items are evenly distributed in the track: first item is on the start line, last item on the end line. Not applies to track_cross_place.