[Unity] Export JAR by Android Studio



Overview

1. Download Andriod Studio
2. Create new project
3. Change view style to "project"
4. Copy your source code into
5. Copy build script
6. Sync project
7. Copy Unity classes.jar
8. Run build script
9. Done!


1. Download Andriod Studio
2. Create new project

Set your package id & no activity.

[Unity] Android Studio JAR

[Unity] Android Studio JAR

3. Change view style to "project"

[Unity] Android Studio JAR

4. Copy your source code

Path: app/src/main/java/package_id

[Unity] Android Studio JAR

5. Copy build script

Paste the script below & modify your source code path & export path.

[Unity] Android Studio JAR

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    sourceSets {
        main {
            java {
                srcDir 'src/main/java/com.scissor.test/'
            }
        }
    }
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
}

task deleteOldJar(type: Delete) {
    delete 'release/LocalNotification.jar'
}

task exportJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')

    rename('classes.jar', 'LocalNotification.jar')
}

exportJar.dependsOn(deleteOldJar, build)
6. Sync project

package com.unity3d.player doesn't exist?

[Unity] Android Studio JAR

7. Copy Unity classes.jar

Mac path:

/Applications/Unity/PlaybackEngines/AndroidPlayer/Variations/mono/Release/Classes/classes.jar

[Unity] Android Studio JAR

8. Run build script

Open gradle window from the right side of Android Studio
and find:
package name/other/exportJar

[Unity] Android Studio JAR

9. Done!

You can find your JAR in the app/release.
Copy to Plugins/Android in your Unity project & test!

[Unity] Android Studio JAR




歡迎您留言與分享!(Welcome for comments or sharing!)

Related Post:

Tagged on: ,