Android Studio不会导出Jar

时间:2018-09-16 08:12:08

标签: java android unity3d plugins jar

我创建一个新的android studio项目,添加新的模块

,我通过此路径获得unity插件 “ D:\ Unity \ Editor \ Data \ PlaybackEngines \ AndroidPlayer \ Variations \ mono \ Release \ Classes”

我将classes.jar添加到mylibrary> libs中 右键单击“ classes.jar”并添加库

edit mylibrary> build.gradle,像这样

apply plugin: 'com.android.library'
android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 15
        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-rc02'
    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/classes.jar')
}
task deleteOldJar(type: Delete) {
    delete 'release/AndroidPlugin.jar'
}
task exportJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    rename('classes.jar', 'AndroidPlugin.jar')
}

exportJar.dependsOn(deleteOldJar, build)

并添加一个Java

package com.example.mylibrary;
import android.app.AlertDialog;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
public class GetUrl extends UnityPlayerActivity {
    public static void Show(final String title, final String content)
    {
        UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
            public void run() {

                AlertDialog.Builder builder = new AlertDialog.Builder(UnityPlayer.currentActivity);
                builder.setTitle(title).setMessage(content).setCancelable(false).setPositiveButton("OK", null);
                builder.show();
            }
        });
    }
}

刷新后,我打开grable菜单,双击createJar,但没有任何文件生成

我正在寻找很多教程,并按照以下步骤尝试几个小时,几乎相同的步骤,但是仍然没有结果,您有什么想法吗? D:

1 个答案:

答案 0 :(得分:1)

删除代码:

task deleteOldJar(type: Delete) {
    delete 'release/AndroidPlugin.jar'
}
task exportJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    rename('classes.jar', 'AndroidPlugin.jar')
}

exportJar.dependsOn(deleteOldJar, build)

然后只需双击mygrabrary gradle操作下的build函数。然后从mylibrary-debug.aar获取新创建的/YourAndroidProject/mylibrary/build/outputs/aar/mylibrary-debug.aar文件,并将其拖到unity项目中的Plugins/Android文件夹中。