InMobi intergration in Unity game error for android - java

I'm trying to integrate InMobi into my unity game to show ads. I made a jar library and call needed method via JNI in unity but getting the following error:
Android Java Exception: java.lang.NoClassDefFoundError‏
My method is static because unity doesn't do Call() for me, so I can do only CallStatic().
public static void ShowInMobi(final Context context)
{
//com.google.ads.mediation.inmobi.InMobiAdapter.disableHardwareAcceleration();
//((Activity) context).runOnUiThread(new Runnable() {
// public void run() {
String CLASS_TO_LOAD ="com.inmobi.commons.InMobi";
try
{
Class<?> newClass = Class.forName(CLASS_TO_LOAD);
System.out.println("Class "+newClass+" found successfully!");
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
System.out.println("Class "+CLASS_TO_LOAD+" not found!");
}
catch (Throwable any)
{
System.out.println("Unexpected error! "+any);
}
if(interstitialInMobi==null)
{
com.inmobi.commons.InMobi.initialize((Activity) context, "my_ad_unit_id");
interstitialInMobi = new IMInterstitial((Activity) context, "my_ad_unit_id");
interstitialInMobi.loadInterstitial();
}
else
{
if (interstitialInMobi.getState() == IMInterstitial.State.READY){
interstitialInMobi.show();
interstitialInMobi.loadInterstitial();
}
}
//}
//});

Sohan from InMobi here
Looks like you are trying to use the native SDK directly in Unity. InMobi has a Unity plugin that you can use instead. The plugin acts as the mediator between the native SDK and your app.
You can check this link for further integration details.

Related

How to print receipt with PAX a 920?

I have Pax A920 which runs with android .
So how to using printing service in java?
I suggest you to use the Neptune api. you can google pax 920 neptune api demo and the fist link that shows up (https://docs.hips.com/docs/pax-a920) contains a demo that shows all the basic functions (including the printer) and you can run it on your device:
In the Application you first need a function to retrieve the IDAL:
public static IDAL getDal() {
if(dal == null){ //dal is a private static IDAL variable of the application
try {
dal = NeptuneLiteUser.getInstance().getDal(context);
} catch (Exception e) {}
}
return dal;
}
then in your activity you can just do the following:
try {
IPrinter printer= MyApp.getDal().getPrinter();
printer.init();
printer.printStr("Your text",null);
printer.start();
} catch (PrinterDevException e) {
e.printStackTrace();
}

Google App Engine - cannot resolve method 'execute()', but project compiles

I'm writing an Android client that works with a Google App Engine backend. The client compiles and runs just fine, but the execute() method is yet unidentified.
My AsyncTask's doInBackground(...):
#Override
protected String doInBackground(Pair<Context, String>... params) {
context = params[0].first;
if(mService == null) {
DatastoreRequests.Builder builder = new DatastoreRequests.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
.setRootUrl(myRootUrl);
mService = builder.build();
}
try {
return String.valueOf(mService.sayHi(params[0].second).execute()); // 'execute' is red colored
} catch (IOException e) {
return e.getMessage();
}
}
sayHi:
public DatastoreRequests.SayHi sayHi(String name) throws IOException {
DatastoreRequests.SayHi result = new DatastoreRequests.SayHi(name);
this.initialize(result);
return result;
}
As I mentioned, the code does run, and for example, when removing the String.valueOf() method - the build fails. So, why is it unrecognized? Any explanation for such behavior and how to solve it? Thanks.
I'm working with IntelliJ IDEA 2016.1.1.

java.lang.NoClassDefFoundError Android Studio Unity

I'm having some troubles when I try to generate a library that contains another one in Android Studio. First of all I am using Android Studio 2.0 and Unity 5.3.4f1. What I want to do is integrate FFMpeg in Unity so I decided to create my own library that use FFMpeg library as an intermediary. The FFMpeg library is here.
To start I created a new empty project in Android Studio and inside of it, created a new module, which will be my library, using New->Module->Android Library and named it "ffmpegcodec". After that I opened build.gradle file inside the new module folder and paste:
compile 'com.writingminds:FFmpegAndroid:0.3.2'
inside dependencies brackets, and click Sync (It did not show any error).
After that create a new Java Class inside src/main/java/package-name/ and named it FFMpegCodec. Inside this paste this code:
public class FFMpegCodec {
private static FFmpeg ffmpeg;
private static Context context;
private static FFMpegCodec INSTANCE = null;
public FFMpegCodec(){
INSTANCE = this;
}
public static FFMpegCodec instance(){
if(INSTANCE == null){
INSTANCE = new FFMpegCodec();
}
return INSTANCE;
}
public void setContext(Context ctx){
this.context = ctx;
}
public void loadFFMpegBinary() {
try {
if (ffmpeg == null) {
ffmpeg = FFmpeg.getInstance(context);
}
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
#Override
public void onFailure() {
Log.e("FFMPEG", "ffmpeg : NOT correct Loaded");
}
#Override
public void onSuccess() {
Log.e("FFMPEG", "ffmpeg : correct Loaded");
}
});
} catch (FFmpegNotSupportedException e) {
} catch (Exception e) {
}
}
public void execFFmpegCommand(final String[] command) {
try {
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
#Override
public void onFailure(String s) {
Log.e("FFMPEG", "FAILED with output : " + s);
}
#Override
public void onSuccess(String s) {
Log.e("FFMPEG", "SUCCESS with output : " + s);
}
#Override
public void onProgress(String s) {
Log.e("FFMPEG", "Started command : ffmpeg " + command);
Log.e("FFMPEG", "progress : " + s);
}
#Override
public void onStart() {
Log.e("FFMPEG", "Started command : ffmpeg " + command);
}
#Override
public void onFinish() {
Log.e("FFMPEG", "Finished command : ffmpeg " + command);
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
}
}
It basically generates an instance of FFmpeg and makes calls of ffmpeg commands.
Once I have my lib done I decided to test it in my project so I include my lib in my app graddle using:
compile project(':ffmpegcodec')
After that I just paste this code to my MainActivity:
public class MainActivity extends AppCompatActivity {
FFMpegCodec ffmpeg;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button execCommandButton = (Button) findViewById(R.id.execCommandButton);
ffmpeg = FFMpegCodec.instance();
execCommandButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "This is a Toast!!", Toast.LENGTH_SHORT).show();
ffmpeg.setContext(MainActivity.this);
ffmpeg.loadFFMpegBinary();
String []cmd = new String[1];
cmd[0] = "-version";
ffmpeg.execFFmpegCommand(cmd);
}
});
}
After that, I run my project and when I press the button it returns that everythings its ok, showing ffmpeg version.
Once I have check that my lib works I decide to move it to Unity so copy the ffmpegcodec-realese.arr file inside ffmpegcodec/build/outputs/aar folder and paste it into my Unity project. Then I wrote an C# script to use my lib that contains this:
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using System.Collections;
using System.Diagnostics;
public class ScreenRecorder {
private AndroidJavaObject unityActivity = null;
private AndroidJavaObject captureObject = null;
// Use this for initialization
public ScreenRecorder () {
try{
using (AndroidJavaClass unityPlayerActivityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
unityActivity = unityPlayerActivityClass.GetStatic<AndroidJavaObject>("currentActivity");
}
AndroidJavaClass captureClass = new AndroidJavaClass ("com.promineostudios.ffmpegcodec.FFMpegCodec");
if (captureClass != null) {
captureObject = captureClass.CallStatic<AndroidJavaObject>("instance");
captureObject.Call("setContext", unityActivity);
captureObject.Call("loadFFMpegBinary");
}
}catch(Exception ex){
UnityEngine.Debug.Log(ex);
}
}
}
The problems comes here. When I create a class instance using:
AndroidJavaClass captureClass = new AndroidJavaClass ("com.promineostudios.ffmpegcodec.FFMpegCodec");
It creates an instance correctly, and also when I create an object using:
captureObject = captureClass.CallStatic<AndroidJavaObject>("instance");
But when I try to get access to FFMpeg library methods like in "setContext" it fails and returns this:
UnityEngine.AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/github/hiteshsondhi88/libffmpeg/FFmpeg;
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/github/hiteshsondhi88/libffmpeg/FFmpeg;
at com.promineostudios.ffmpegcodec.FFMpegCodec.loadFFMpegBinary(FFMpegAndroidCodec.java:39)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.a(Unknown Source)
at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.github.hiteshsondhi88.libffmpeg.FFmpeg" on path: DexPathList[[zip file "/data/app/com.promineostudios.ffmpegmodule-1/base.apk"],nativeLibraryDirectories=[/data/app/com.promineostudios.ffmpegmodule-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.promineostudios.ffmpegcodec.FFMpegCodec.loadFFMpegBinary(FFMpegAndroidCodec.java:39) 
at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 
at com.unity3d.player.UnityPlayer.a(Unknown Source) 
at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
I think that the problem is in when I export my lib into Unity but I do not know what is going wrong. If anybody could help me I will be really appreciated.
Thanks and excuse me for my English.
I know you're no longer working on this project Nestoraj, however I have figured out a solution:
The error you're getting is caused by the UnityPlayerActivity not finding the source for com/github/hiteshsondhi88/libffmpeg/FFmpeg so in order to fix that you must put the 'com.writingminds:FFmpegAndroid:0.3.2' jar file inside your Unity project's Assets/Plugins/Android folder
After doing that and running the project, you're still going to get an error loading the ffmpeg binary file, this is because it's also not properly packaged in Unity, to fix this you need to export your project to Gradle/Android Studio, and then inside your src/main/jniLibs directory you have to place the ffmpeg .so binary files, according to each architecture so jniLibs/armeabi-v7a/libARM_ARCH.so jniLibs/armeabi/libARM_ARCH.so etc. Then you must also place the ffmpeg object files inside src/main/assets and again according to each architecture like so : src/main/assets/armeabi-v7a/ffmpeg etc.
Once those 2 steps are done you should be able to run your project in Android Studio and load the ffmpeg binary inside your Unity project

Launch urls based on different versions of java

I am in a situation where i need to create a simple launcher that allows me too select which web address to launch with different versions of java. I have researched several sites. Having the user change windows settings is not an option as it would generate too many support calls or user does not have priviliges. What i want is a programming way to set or change the version of java being used to launch a url. I have seen proprietary systems make launchers with a gui that allows you to change address and java version and then launch it in a browser. I am new to development and obviously having trouble understanding which techniques to use.
Will you please point me in the right direction. I am comfortable writing guis(in c# or java) I just need to know how to write the function for the launch button?
function launchbutton(url, javaversion)
{
If (javaversionselect == 1.3)
{
open url in default browser running java version 1.3
}
If (javaversionselect == 1.4)
{
open url in default browser running java version 1.4
}
If (javaversionselect == 1.5)
{
open url in default browser running java version 1.5
}
If (javaversionselect == 1.6)
{
open url in default browser running java version 1.6}
}
Bare Bones Browser Launcher will detect the java version and use the appropriate calls.
http://www.centerkey.com/java/browser/
You wan't be able to change the version of java that for example 'IE' or 'Chrome' use from withing your application, your only solutions would be to use some kind of embedded browser
jBrowser
XPCOM from Mozilla
Browse source and look on how Eclipse embedded their browser
You can write an applet that does it. Compile something like this, using javac -target 1.3:
public class Redirector
extends Applet {
#Override
public void start() {
String newURL;
Package pkg = Object.class.getPackage();
if (pkg.isCompatibleWith("1.7")) {
newURL = "java17.html";
} else if (pkg.isCompatibleWith("1.6")) {
newURL = "java16.html";
} else if (pkg.isCompatibleWith("1.5")) {
newURL = "java15.html";
} else if (pkg.isCompatibleWith("1.4")) {
newURL = "java14.html";
} else {
newURL = "java13.html";
}
try {
getAppletContext().showDocument(new URL(newURL));
} catch (MalformedURLException e) {
showStatus(e.toString());
}
}
}
If you really want let the user choose the Java version for himself, you can create UI elements in your applet for that:
public class Redirector
extends Applet
implements ActionListener {
private Choice list;
#Override
public void init() {
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
list = new Choice();
list.add("1.7");
list.add("1.6");
list.add("1.5");
list.add("1.4");
list.add("1.3");
Button button = new Button("Launch");
button.addAtionListener(Redirector.this);
add(new Label("Java version:"));
add(list);
add(button);
}
});
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void actionPeformed(ActionEvent event) {
String newURL;
String version = list.getSelectedItem();
if (version.equals("1.7")) {
newURL = "java17.html";
} else if (version.equals("1.6")) {
newURL = "java16.html";
} else if (version.equals("1.5")) {
newURL = "java15.html";
} else if (version.equals("1.4")) {
newURL = "java14.html";
} else {
newURL = "java13.html";
}
try {
getAppletContext().showDocument(new URL(newURL));
} catch (MalformedURLException e) {
showStatus(e.toString());
}
}
}

How to use platformRequest to call a website Url?

I am making a j2me website launcher for an url "http://www.google.com".
I am using this code:
public class LuncherMidlet extends MIDlet {
boolean Isflage;
public void startApp() {
Isflage = false;
try {
Isflage = platformRequest("http://www.google.com");
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
if(Isflage){
destroyApp(true);
notifyDestroyed();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
This code is working fine, but when I try to close the browser of mobile it shows a message for connect to server. If I say no then it again open the this j2me launcher again. It's not exiting from mobile browser. My launcher reaches in a loop.
Kindly suggest me on this issue.
When you invoke platformRequest(), it would call to native apps, and on close on browser it is browser's stuff that is being invoked. You can't change it.

Categories