当我使用Android Studio导出jar时,没有jar文件



我按照本教程为 unity3d 导出 jar 文件,我参考这个来解决我的问题,但是,我仍然在项目中找不到任何 jar 文件,发布目录为空。

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)

这就是结果:

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。

有什么帮助吗?

我想通了。目前Android Studio不放类.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')
}

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

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

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

我不得不使用路径: 构建/中间体/compile_library_classes_jar/发布/

我正在使用安卓工作室 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')
}

最新更新