0

been trying to generate Jar file of my existing Jetpack Compose project. I want to:

  1. Build jar file
  2. Upload that build to Jenkins Server.

I want to know, what is the correct way of doing it. I have been trying with this, but it still fails.

android {
    namespace = "com.xxx.xxx"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.xxx.xxx"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

    }
    tasks.withType<Jar> {
        enabled = true
        manifest {
            attributes["Main-Class"] = namespace
        }
    }
}

dependencies {
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.androidx.lifecycle.runtime.ktx)
        ...
}
        // Task to create a JAR file
    task createJar(type: Jar) {
        archiveBaseName = 'mycomposeapp'
        archiveVersion = '1.0.0'
        from {
            configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
        }
        with jar
    }

Any help here, please?

Can set up Jenkins file, but what to do in build.gradle is what making me mad :(

IDE LOOKS LIKE THIS...

5
  • Akash can you post your complete gradle file and where are you calling createJar task ?
    – Bob
    Commented Jun 17 at 12:24
  • @BobSmith, android { compileSdk = 34 defaultConfig { applicationId = "com.xxxx.xxxx.xxxx" minSdk = 24 } buildTypes {..} compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } kotlinOptions {jvmTarget = "1.8"} } dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) implementation(libs.androidx.lifecycle.runtime.ktx) ... } task jar (type: Jar) { archiveBaseName = 'your-jar-name' archiveVersion = '1.0' from android.sourceSets.main.java.srcDirs include 'xxx.xxx' }
    – Akash Nair
    Commented Jun 18 at 10:00
  • @BobSmith, Done... Edited my question
    – Akash Nair
    Commented Jun 18 at 11:03
  • Akash line no 34 having 3 dots did you copied it from somewhere. Don't use unnecessary dots, commas and brackets it will break your system. Learn how groovy gradle works. If its difficult switch to Kotlin Based DSL
    – Bob
    Commented Jun 18 at 11:13
  • @BobSmith I have removed most of the business codes from the Gradle... Also the issue is with creating Jar which I'm not able to :(
    – Akash Nair
    Commented Jun 18 at 13:01

0