Build an Android project and get a `.apk` file on a Debian 11 command line

embedded/2024/10/18 8:16:35/

You can build an Android project and get a .apk file on a Debian 11 command line without using Android Studio. The process involves using the Android SDK command-line tools (sdkmanager, adb, and gradle).

Here’s a step-by-step guide to building the ??? Android project (or any other Android project) on Debian 11:

1. Install Java Development Kit (JDK)

??? Android requires JDK 8 or newer. You can install the JDK using the following command:

sudo apt update
sudo apt install openjdk-11-jdk

2. Install Android SDK Command-Line Tools

Download the Android SDK command-line tools. You can do this by visiting the Android SDK download page or by running:

wget https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip
ed2k://|file|android-sdk-commandlinetools-linux-9477386_latest.zip|133507477|9B0150B86C257EB841527537951CFDF2|/

Extract the SDK tools and move them to your desired location:

unzip commandlinetools-linux-9477386_latest.zip
sudo mkdir -p /opt/android-sdk/cmdline-tools
sudo mv cmdline-tools /opt/android-sdk/cmdline-tools/latest

Add the Android SDK to your PATH by editing the .bashrc file:

echo "export ANDROID_SDK_ROOT=/opt/android-sdk" >> ~/.bashrc
echo "export PATH=\$PATH:/opt/android-sdk/cmdline-tools/latest/bin:/opt/android-sdk/platform-tools" >> ~/.bashrc
source ~/.bashrc

3. Install Required SDKs and Build Tools

Now, use the SDK manager to install necessary packages like platform-tools, build-tools, and SDK platforms:

sdkmanager --install "platform-tools" "platforms;android-30" "build-tools;30.0.3"

Adjust the SDK and build tools versions according to the project’s requirements (you can check build.gradle for details).

4. Clone the Project

Clone the ??? Android repository:

git clone https://github.com/????????????/????????????-android.git
cd ????????????-android

5. Install Gradle

Debian repositories might not have the latest Gradle version. Install the required version specified in the gradle/wrapper/gradle-wrapper.properties file by running:

sudo apt install gradle

Alternatively, you can use the Gradle wrapper bundled with the project:

./gradlew

6. Build the Project

Run the following Gradle command to build the APK:

./gradlew assembleRelease

This command will generate the APK file in the app/build/outputs/apk/release/ directory.

7. Sign the APK (Optional)

If you want to sign the APK for release, you will need a keystore. You can create one with:

keytool -genkey -v -keystore my-release-key.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias my-key-alias

Sign the APK using apksigner:

apksigner sign --ks my-release-key.keystore --out app-release-signed.apk app/build/outputs/apk/release/app-release-unsigned.apk

8. Run or Install the APK

Once the APK is built, you can install it on your Android device using ADB:

adb install app-release-signed.apk

That’s it! You should now have a .apk file generated without needing Android Studio.

To upgrade from JDK 11 to JDK 17 on your Debian system, you can follow these simple steps to install JDK 17 and set it as the default. Here’s how to do it efficiently:

Step-by-Step Process to Upgrade to JDK 17

1. Install JDK 17

Use the Debian package manager to install OpenJDK 17:

sudo apt update
sudo apt install openjdk-17-jdk

This will install JDK 17 alongside your current JDK 11 version.

2. Check Installed Java Versions

After installation, you can check the installed Java versions by running:

sudo update-alternatives --config java

This will display all installed Java versions.

3. Switch to JDK 17

You’ll see a list of installed JDKs and a prompt to choose which one to use. Select the number corresponding to JDK 17 to set it as the default version.

For example, if the list looks like this:

There are 2 choices for the alternative java (providing /usr/bin/java).Selection    Path                                           Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java     1111      auto mode1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java     1111      manual mode2            /usr/lib/jvm/java-17-openjdk-amd64/bin/java     1112      manual modePress <enter> to keep the current choice[*], or type selection number:

Enter the number corresponding to JDK 17 (in this case, 2).

4. Verify the Java Version

To confirm that JDK 17 is now the active version, run:

java -version

You should see something like:

openjdk version "17.x.x" OpenJDK Runtime Environment (build ...)
5. Update JAVA_HOME Environment Variable (Optional)

If you rely on the JAVA_HOME environment variable in your build, make sure it points to JDK 17. Add the following line to your ~/.bashrc or ~/.profile file:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

Then, reload the shell:

source ~/.bashrc

6. Run the Build Again

Now that you’re using JDK 17, you can re-run your Gradle build:

./gradlew build

This should resolve the issue with the Firebase dependency that requires a Java 17 runtime.

Downgrading to Gradle 8.x is a simpler and effective approach, especially if you just want to avoid dealing with compatibility issues related to future versions like Gradle 9.0.

Here’s how you can downgrade Gradle and switch to a specific version:

1. Install a Specific Version of Gradle (e.g., 8.x)

You can manually install a specific version of Gradle (like 8.x) by following these steps:

  1. Download the Gradle 8.x distribution:
    Go to the Gradle releases page and download the ZIP for the desired 8.x version. For example, download Gradle 8.10 if you want to use that.

    wget https://services.gradle.org/distributions/gradle-8.10-bin.zip
    
  2. Unzip the downloaded Gradle:
    Unzip the downloaded file in a directory of your choice (for example, /opt/gradle).

    sudo mkdir /opt/gradle
    sudo unzip gradle-8.10-bin.zip -d /opt/gradle
    
  3. Set up the environment variable:
    Point your system to use this specific version of Gradle by updating your PATH environment variable.

    Add the following line to your ~/.bashrc (or ~/.profile):

    export PATH=/opt/gradle/gradle-8.10/bin:$PATH
    

    Then reload your shell:

    source ~/.bashrc
    
2. Verify the Installed Gradle Version

To make sure the correct version of Gradle is now active, run:

gradle -v

This should show you that Gradle 8.x is being used.

3. Switch Between Gradle Versions

If you later need to switch between Gradle 9.0 and 8.x, you can:

  • Update the PATH environment variable to point to the version you need.
  • Use Gradle Wrapper (gradlew) to specify a particular version for your project.

For example, to use Gradle 8.x for your project via the Gradle Wrapper, you can update the wrapper configuration:

./gradlew wrapper --gradle-version 8.x

This way, your project will always use Gradle 8.x regardless of the system-wide version installed.


http://www.ppmy.cn/embedded/128398.html

相关文章

【Python】线程指南 状态转化 同步 通信 条件变量 (附带无偿学习资料)

1. 线程基础 1.1. 线程状态 线程有5种状态&#xff0c;状态转换的过程如下图所示&#xff1a; 1.2. 线程同步&#xff08;锁&#xff09; 多线程的优势在于可以同时运行多个任务&#xff08;至少感觉起来是这样&#xff09;。但是当线程需要共享数据时&#xff0c;可能存在…

(一)Mysql篇---Mysql整体架构

MySql框架浅析 首先&#xff0c;上一张图先让各位看看大致结构&#xff1a; 从上到下&#xff0c;依次说一下结构&#xff1a; 连接层&#xff1a;这里主要是处理客户端和数据库连接的&#xff0c;直接使用的Tomcat的连接池&#xff0c;可以调整最大连接数&#xff1b; 服务…

python 爬虫 入门 一、基础工具

目录 一&#xff0c;网页开发者工具的使用 二、通过python发送请求 &#xff08;一&#xff09;、get &#xff08;二&#xff09;、带参数的get &#xff08;三&#xff09;、post 后续&#xff1a;数据解析 一&#xff0c;网页开发者工具的使用 我们可以用 requests 库…

{输电线路监控设备功耗}

对于一款输电线路监控设备&#xff0c;由于装在铁塔上面&#xff0c;对于功耗&#xff0c;电网上面的应用&#xff0c;尤为重要&#xff0c;如何得做到低功耗&#xff0c;一直大家研究的地方&#xff0c;解决了功耗&#xff0c;基本产品成功了一半&#xff0c;而合方圆在电网行…

执行jar文件no main manifest attribute错误

执行jar文件no main manifest attribute错误 问题是由于maven打包时候没有指定主启动程序&#xff0c;或下方配置中多余true配置跳过主程序配置 对应找到build中的所有有关true的删除&#xff0c;再重新打包即可

SpringBoot中集成海康威视SDK实现布防报警数据上传/交通违章图片上传并在linux上部署(附示例代码资源)

场景 需对接海康威视交通产品中的交通违章检测功能&#xff0c;实现车辆闯红灯时获取抓拍数据(车牌号)并获取上传的抓拍图片。 根据其官方资料设备网络SDK使用手册中说明&#xff0c;此流程需要可以通过报警布防方式进行。 访问官方下载SDK文档等资料 海康威视-引领智能物联…

重学SpringBoot3-集成Spring Security(三)

更多SpringBoot3内容请关注我的专栏&#xff1a;《SpringBoot3》 期待您的点赞&#x1f44d;收藏⭐评论✍ 重学SpringBoot3-集成Spring Security&#xff08;三&#xff09; 1. 防范CSRF&#xff08;跨站请求伪造&#xff09;1.1 演示效果1.2 关闭 CSRF 防护 2. 防范XSS&#x…

搭建Elasticsearch集群

一. 集群的结构 1.单点的问题 单点的Elasticsearch存在哪些可能出现的问题呢? 单台机器存储容量有限,无法实现高存储。容易出现单点故障,无法实现高可用。单服务的并发处理能力有限,无法实现高并发所以,为了应对这些问题,我们需要对Elasticsearch搭建集群。 2.数据分片…