【问题标题】:There is no jar file when I use Android Studio to export jar使用Android Studio导出jar时没有jar文件
【发布时间】:2021-06-13 08:00:31
【问题描述】:

我按照tutorial 导出 jar 文件供 unity3d 使用,并参考this 解决我的问题,但是,我仍然在项目中找不到任何 jar 文件,发布目录为空。

我的 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)

结果如下:

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'.

我想我成功导出了 jar 文件,但是发布目录中有空,这是有线的。顺便说一句,我使用的是 macOS Mojave 10.14,我的 Android Studio 版本是 3.2。

有什么帮助吗?

【问题讨论】:

    标签: java android


    【解决方案1】:

    我想通了。目前 Android Studio 没有将 classes.jar 放在 build/intermediates/bundles/release/ 中,它在 build/intermediates/packaged-classes/release/ 中。所以这样做:

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

    【讨论】:

      【解决方案2】:

      我不得不使用路径: build/intermediates/compile_library_classes_jar/release/

      我使用的是 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')
      }
      

      【讨论】:

        【解决方案3】:

        如果您使用的是 Android Studio v4.2 及更高版本,请更新

        这个

        from('build/intermediates/compile_library_classes_jar/release/')
        

        from('build/intermediates/aar_main_jar/release/')
        

        【讨论】:

          猜你喜欢
          • 2016-11-22
          • 2019-02-20
          • 1970-01-01
          • 1970-01-01
          • 2016-04-05
          • 1970-01-01
          • 1970-01-01
          • 2015-02-09
          • 2016-02-13
          相关资源
          最近更新 更多