可Android的工作室用于创建单位插件兼容的JAR出库的项目?插件、工作室、单位、项目

2023-09-06 04:22:18 作者:26.稚于最初

在使用Unity3d,原生(纯Java)的Andr​​oid功能可以通过插件访问。正如文档描述,

When using Unity3d, "native" (pure-java) Android functionality can be accessed via Plugin. As described in the documentation,

有多种方法可以创建一个Java插件,但结果在每种情况下是,你最终有一个.jar文件包含.class文件给你的插件

There are several ways to create a Java plugin but the result in each case is that you end up with a .jar file containing the .class files for your plugin

当我在Eclipse中创建一个Android应用程序项目,并设置它是一个库,它会自动生成在 A 的.jar 文件仓文件夹。我明白这是在Android工具链的情况下的临时文件,但是这是一个团结的需要,以看班,并建立它自己的内部JNI魔术文件。 (整个过程被概括得非常好这里的情况下更加清晰有必要对这一进程。 )

When I create an Android Application Project in eclipse, and set it is a library, it automatically generates a .jar file in the bin folder. I understand that this is a temporary file in the context of the Android toolchain, but this is the file that Unity needs in order to see the classes and build up it's own internal JNI magic. (The entire process is outlined very well here in case more clarity is needed on that process.)

不幸的是,尽可能接近我可以告诉大家,Android的Studio不会生成此文件。有没有一种方法,我可以告诉它给我这个文件,或者一些其他的方式来产生code表示团结就能使用?

Unfortunately, as near as I can tell, Android Studio does not generate this file. Is there a way I can tell it to give me this file, or perhaps some other way to generate code that Unity will be able to use?

推荐答案

您可以创建一个使用Android的Studio中的jar文件。 只需在您的应用程序的build.gradle文件添加这些任务。

You can create a jar file using Android Studio. Just add these tasks in your app's build.gradle file.

//task to delete the old jar
task deleteOldJar(type: Delete) {
    delete 'build/libs/AndroidPlugin.jar'
}

//task to export contents as jar
task exportJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    ///Give whatever name you want to give
    rename('classes.jar', 'AndroidPlugin.jar')
}

exportJar.dependsOn(deleteOldJar, build)

一旦添加上述各行可以导出使用相同名称的任务罐子。 你可以通过这个职位上TGC这里如何创建一个Android插件统一采用Android工作室

Once you add the above lines you can export the jar using the task of the same name. You can go through this post on TGC here on how to create an Android Plugin For Unity using Android Studio

 
精彩推荐
图片推荐