A similar question has already been asked, but was undeservedly forgotten. Moreover, EnSO has an answer to this question, but for 2013 and now it does not work.

The bottom line. We need to pack several classes with a third-party library in the jar, we write a plugin for Unity3D on Android.

They tried to do it like this https://habrahabr.ru/post/226987/

EnSO Solution Write the following code in build.gradle

task clearJar(type: Delete) { delete 'build/libs/myCompiledLibrary.jar' } task makeJar(type: Copy) { from('build/bundles/release/') into('build/libs/') include('classes.jar') rename ('classes.jar', 'myCompiledLibrary.jar') } makeJar.dependsOn(clearJar, build) 

Then we use our task MakeJar in the task gradle and it starts doing something. Makes about 20 seconds, in the process gives

 Executing tasks: [makeJar] Configuration on demand is an incubating feature. Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2340Library UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72340Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42340Library UP-TO-DATE :app:prepareComAndroidSupportSupportVectorDrawable2340Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE :app:compileDebugJavaWithJavac UP-TO-DATE :app:compileDebugNdk UP-TO-DATE :app:compileDebugSources UP-TO-DATE :app:mergeDebugShaders UP-TO-DATE :app:compileDebugShaders UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:transformClassesWithDexForDebug UP-TO-DATE :app:mergeDebugJniLibFolders UP-TO-DATE :app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE :app:processDebugJavaRes UP-TO-DATE :app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE :app:validateSigningDebug :app:packageDebug UP-TO-DATE :app:assembleDebug UP-TO-DATE :app:checkReleaseManifest :app:prepareReleaseDependencies :app:compileReleaseAidl UP-TO-DATE :app:compileReleaseRenderscript UP-TO-DATE :app:generateReleaseBuildConfig UP-TO-DATE :app:generateReleaseResValues UP-TO-DATE :app:generateReleaseResources UP-TO-DATE :app:mergeReleaseResources UP-TO-DATE :app:processReleaseManifest UP-TO-DATE :app:processReleaseResources UP-TO-DATE :app:generateReleaseSources UP-TO-DATE :app:incrementalReleaseJavaCompilationSafeguard UP-TO-DATE :app:compileReleaseJavaWithJavac UP-TO-DATE :app:compileReleaseNdk UP-TO-DATE :app:compileReleaseSources UP-TO-DATE :app:lintVitalRelease :app:mergeReleaseShaders UP-TO-DATE :app:compileReleaseShaders UP-TO-DATE :app:generateReleaseAssets UP-TO-DATE :app:mergeReleaseAssets UP-TO-DATE :app:transformClassesWithDexForRelease UP-TO-DATE :app:mergeReleaseJniLibFolders UP-TO-DATE :app:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE :app:processReleaseJavaRes UP-TO-DATE :app:transformResourcesWithMergeJavaResForRelease UP-TO-DATE :app:packageRelease UP-TO-DATE :app:assembleRelease :app:assemble :app:lint Ran lint on variant release: 7 issues found Ran lint on variant debug: 7 issues found Wrote HTML report to file:///C:/Users/user/AndroidStudioProjects/Sensors/app/build/outputs/lint-results-debug.html Wrote XML report to file:///C:/Users/user/AndroidStudioProjects/Sensors/app/build/outputs/lint-results-debug.xml :app:incrementalDebugUnitTestJavaCompilationSafeguard UP-TO-DATE :app:preDebugUnitTestBuild UP-TO-DATE :app:prepareDebugUnitTestDependencies :app:compileDebugUnitTestJavaWithJavac UP-TO-DATE :app:processDebugUnitTestJavaRes UP-TO-DATE :app:compileDebugUnitTestSources UP-TO-DATE :app:mockableAndroidJar UP-TO-DATE :app:assembleDebugUnitTest UP-TO-DATE :app:testDebugUnitTest UP-TO-DATE :app:incrementalReleaseUnitTestJavaCompilationSafeguard UP-TO-DATE :app:preReleaseUnitTestBuild UP-TO-DATE :app:prepareReleaseUnitTestDependencies :app:compileReleaseUnitTestJavaWithJavac UP-TO-DATE :app:processReleaseUnitTestJavaRes UP-TO-DATE :app:compileReleaseUnitTestSources UP-TO-DATE :app:assembleReleaseUnitTest UP-TO-DATE :app:testReleaseUnitTest UP-TO-DATE :app:test UP-TO-DATE :app:check :app:build :app:clearJar UP-TO-DATE :app:makeJar UP-TO-DATE BUILD SUCCESSFUL 

As a result, there is nothing new in the libs folder - only our old classes library, which we took from Unity. Creation date is old, does not change.

If the method is working, that is, the assumption - since 2013 many versions of Android Studio have been released, the system has changed a lot and maybe we are taking the raw data for Gradle from there!

If so, explain how to edit the code provided above in accordance with the version of Android Studio 2.2.

If this is not the case, tell me how to create a jar-archive from the classes I created and the external jar of the Unity library.

It would be great if the answer was universal - i.e. not outdated, as the answer to this question is outdated at EnSO 2013. Something like - we are looking for such a file in the Android Studio folder. The folder in this file is specified in Android Studio. So that no matter how the internal structure of the android project changes, you can always apply the desired method.

Added - you can not from Android Studio. Just at least somehow create a plugin for Unity, at least jar, at least aar, at least on some software.

    1 answer 1

    Just create a standard project for Android. First you need to copy classes.jar from the Unity installation directory. In the project, create a daddy libs and throw classes.jar there.

    Customize the gradle build script. Delete the lines:

     applicationId "..." versionCode 1 versionName "1.0" 

    Change the line:

     apply plugin: 'com.android.application' 

    on:

     apply plugin: 'com.android.library' 

    add to dependencies {} block

     // классы, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΡ‹ скопировали ΠΈΠ· Unity Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΎΡ€ΠΈΠΈ // Π½Π΅ Π²ΠΊΠ»ΡŽΡ‡Π°Π΅ΠΌ ΠΈΡ… Π² ΠΈΡ‚ΠΎΠ³ΠΎΠ²ΡƒΡŽ сборку, Ρ‡Ρ‚ΠΎΠ± ΠΏΠΎΡ‚ΠΎΠΌ Π½Π΅ Π±Ρ‹Π»ΠΎ ΠΊΠΎΠ½Ρ„Π»ΠΈΠΊΡ‚ΠΎΠ² provided files('libs/classes.jar') 

    Editing AndroidManifest.xml Also delete all unnecessary. As a result, there will be something like this:

      <application android:allowBackup="true" android:supportsRtl="true" android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" > </application> </manifest> 

    Build aar

    To bring down the project. Item AssembleRelease in the Gradle menu. Now copy the resulting aar to / Plugins / Android.


    Selected the main information from the article

    http://suvitruf.ru/2016/02/17/3893/