简体   繁体   中英

How to use a jar in Unity3D?

I have a jar library that i created. It can be integrated in any android app and it works like this:

String token="<SOME_TOKEN>";
DeviceIdentifier edDevice = new DeviceIdentifier(
                            this.getApplicationContext(),token);
edDevice.update();

DeviceIdentifier class os a class in the jar.

now i want to make that jar work with Unity3d, i searched the web and couldn't find anything

what is the correct way to integrate it?

Getting files from a jar file needs to be accessed from the WWW class and written to a readable path, Here is a code example that allows you to copy files out of jar. Then use your IO framework to access those files.

This particular code accesses the jar file created from the streaming assets folder. If you have a custom jar file you may need to alter the path that the WWW points to.

public static IEnumerator ExtractFileFromJar(string filename, string filepath)
{
    WWW fileFromJar = new WWW("jar:file://" + Application.dataPath + "!/assets/" + filename);
    yield return fileFromJar;
    File.WriteAllBytes(filepath, fileFromJar.bytes);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM