Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is no jar file when I use Android Studio to export jar

Tags:

java

android

I followed this tutorial to export jar file for unity3d using and I referred this to solve my issue, however, I still can't find any jar file in the project, the release directory is empty.

My build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    defaultConfig {
//        applicationId "com.aoshitang.demo"
        minSdkVersion 21
        targetSdkVersion 28
//        versionCode 1
//        versionName "1.0"
//        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation files('libs/unityClasses.jar')
}

task clearJar(type: Delete) {
    delete 'release/AndroidSensorPlugin.jar'
}

task makeJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    rename ('classes.jar', 'AndroidSensorPlugin.jar')
}

makeJar.dependsOn(clearJar, build)

And this is the result:

16:29:44: Executing task 'makeJar'...

Executing tasks: [makeJar]

:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugAidl NO-SOURCE
:app:compileDebugRenderscript UP-TO-DATE
:app:checkDebugManifest UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:packageDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:generateDebugRFile UP-TO-DATE
:app:prepareLintJar UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:javaPreCompileDebug UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:extractDebugAnnotations UP-TO-DATE
:app:mergeDebugConsumerProguardFiles UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:packageDebugAssets UP-TO-DATE
:app:packageDebugRenderscript NO-SOURCE
:app:processDebugJavaRes NO-SOURCE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:transformClassesAndResourcesWithSyncLibJarsForDebug UP-TO-DATE
:app:compileDebugNdk NO-SOURCE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
:app:transformNativeLibsWithSyncJniLibsForDebug UP-TO-DATE
:app:bundleDebugAar
:app:compileDebugSources UP-TO-DATE
:app:assembleDebug
:app:preReleaseBuild UP-TO-DATE
:app:compileReleaseAidl NO-SOURCE
:app:compileReleaseRenderscript
:app:checkReleaseManifest UP-TO-DATE
:app:generateReleaseBuildConfig UP-TO-DATE
:app:generateReleaseResValues UP-TO-DATE
:app:generateReleaseResources
:app:packageReleaseResources
:app:processReleaseManifest
:app:generateReleaseRFile
:app:generateReleaseSources
:app:javaPreCompileRelease UP-TO-DATE
:app:compileReleaseJavaWithJavac UP-TO-DATE
:app:extractReleaseAnnotations UP-TO-DATE
:app:mergeReleaseConsumerProguardFiles UP-TO-DATE
:app:mergeReleaseShaders UP-TO-DATE
:app:compileReleaseShaders UP-TO-DATE
:app:generateReleaseAssets UP-TO-DATE
:app:packageReleaseAssets UP-TO-DATE
:app:packageReleaseRenderscript NO-SOURCE
:app:processReleaseJavaRes NO-SOURCE
:app:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:app:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
:app:compileReleaseNdk NO-SOURCE
:app:mergeReleaseJniLibFolders UP-TO-DATE
:app:transformNativeLibsWithMergeJniLibsForRelease UP-TO-DATE
:app:transformNativeLibsWithSyncJniLibsForRelease UP-TO-DATE
:app:bundleReleaseAar
:app:compileReleaseSources UP-TO-DATE
:app:mergeReleaseResources
:app:verifyReleaseResources
:app:assembleRelease
:app:assemble
:app:lint
Ran lint on variant debug: 0 issues found
Ran lint on variant release: 0 issues found
:app:generateDebugUnitTestSources UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:javaPreCompileDebugUnitTest UP-TO-DATE
:app:compileDebugUnitTestJavaWithJavac UP-TO-DATE
:app:processDebugUnitTestJavaRes NO-SOURCE
:app:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
:app:testDebugUnitTest
:app:generateReleaseUnitTestSources UP-TO-DATE
:app:preReleaseUnitTestBuild UP-TO-DATE
:app:javaPreCompileReleaseUnitTest UP-TO-DATE
:app:compileReleaseUnitTestJavaWithJavac UP-TO-DATE
:app:processReleaseUnitTestJavaRes NO-SOURCE
:app:transformClassesAndResourcesWithPrepareIntermediateJarsForRelease UP-TO-DATE
:app:testReleaseUnitTest
:app:test
:app:check
:app:build
:app:clearJar UP-TO-DATE
:app:makeJar NO-SOURCE

BUILD SUCCESSFUL in 6s
53 actionable tasks: 11 executed, 42 up-to-date
16:29:51: Task execution finished 'makeJar'.

I think I succeeded to export the jar file but there is empty in release directory, that's wired. By the way, I am using macOS Mojave 10.14 and my Android Studio version is 3.2.

Any help?

like image 919
OtakuFitness Avatar asked Dec 17 '22 20:12

OtakuFitness


2 Answers

I figured it out. Currently Android Studio do not put classes.jar in build/intermediates/bundles/release/, it's in build/intermediates/packaged-classes/release/. So do it like this:

task makeJar(type: Copy) {
    from('build/intermediates/packaged-classes/release/')
    into('release/')
    include('classes.jar')
    rename ('classes.jar', 'AndroidSensorPlugin.jar')
}
like image 166
OtakuFitness Avatar answered Dec 20 '22 09:12

OtakuFitness


I had to use the path: build/intermediates/compile_library_classes_jar/release/

I'm using Android Studio 4.1.3

task exportJar(type: Copy) {
    from('build/intermediates/compile_library_classes_jar/release/')
    into('release/')
    include('classes.jar')
    // name the plugin
    rename('classes.jar', 'ToastPlugin.jar')
}
like image 24
Andrew Tite Avatar answered Dec 20 '22 08:12

Andrew Tite