I will explain how to make an executable jar using Android Studio.
Version The OS version is as follows.
Microsoft Windows 10 Home
10.0.18363 N/A build 18363
The versions of Android Studio are as follows.
Android Studio 4.0
Build #AI-193.6911.18.40.6514223, built on May 21, 2020
Runtime version: 1.8.0_242-release-1644-b01 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
The java version is as follows.
java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
Follow the steps below to create a project.
Start Android Studio. Select Start a new Android Studio project. Create a No Activity project. Name it "My Application" (default). Let's say the Language is "Kotlin".
Follow the steps below to add a jar module in your project.
Select File --New --New Module ... Select Java or Kotlin Library. Set the Library name to "lib" (default). Let the Class name be "MyClass".
fun main Open MyClass.kt. Replace the content with the following:
MyClass.kt
package com.example.lib
fun main(args: Array<String>) {}
The screen of the state executed so far is as follows.
build.gradle
Add the following to your lib build.gradle:
build.gradle
jar {
manifest {
attributes("Main-Class": "com.example.lib.MyClassKt")
}
from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
}
Follow the steps below to add a jar task.
Select View --Tool Windows --Gradle. Window is displayed. Double-click My Application --Tasks --build --jar. The build will start.
The screen of the state executed so far is as follows.
You will have a jar in the following path:
MyApplication\lib\build\libs\lib.jar
Open a command prompt. Navigate to the path where lib.jar is located. Run the following command: If you can execute it without error, you can see that you have a jar that can be executed as expected.
java -jar .\lib.jar
Recommended Posts