Java Question My 1st Wrapped lib - Problem

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Hi all.

I am trying to wrap my 1st lib. It is https://github.com/JakeWharton/ProcessPhoenix
I am using the Simple library compiler and have run into this error. I have included my project.

Any help would be appreciated.

Thanks!



upload_2016-4-27_14-6-18.png
 

Attachments

  • ProcessPhoenix-master.zip
    70.6 KB · Views: 240

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Sounds like I need to go back to school... :) I was following the simple library compiler instructions. Maybe I posted in the wrong forum.
 

DonManfred

Expert
Licensed User
Longtime User
Maybe I posted in the wrong forum.
The forum is correct i guess.
But the code you are trying is not what i would expect to see as code.

The java you are editing extends an activity. So it should be as is but you need to write a wrapper for this to call the methods.
Additional all "third-party" code should be expluded when compiling with slc. So i was extecting the wrapperclass in another package.

In my libs it is always de.donmanfred. code from com.google for example i exclude in slc with com.google in the b4a-ignore-field.
de.donmanfred.thisisawrapper,java for example will be used to wrap com.google.thisisthecodefromgoogle.java
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Thanks for the reply @DonManfred

OK, so I think I am starting to understand. What I need is:
1. Compiled code of the class I want to wrap. (A JAR file)
2. A class I create that has the wrapper code in it.

Wrapper:
B4X:
package anywheresoftware.b4a.objects;

import com.jakewharton.processphoenix.ProcessPhoenix;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@Version(1.0f)
//@Permissions(values={"android.permission.INTERNET"})
@ShortName("Phoenix")
@DependsOn(values={"processphoenixt"})
@ActivityObject
public class PhoenixWrapper {
   
    public void Restart(BA ba) {
        ProcessPhoenix.triggerRebirth(ba.context);
    }
   
}

Am I going in the right direction?

Question though. How do I compile the 3rd party ProcessPhoenix class? There is no JAR just source code.

Thanks!!!
 

DonManfred

Expert
Licensed User
Longtime User
you need to add the "original" sources (java) to your project.
Say you add com.google.somewhat then you need to add com.google in b4a ignore.

for this here: you are using anwheresoftware.b4a.objects as packagename
you added com.jakewharton.somewhat
You need to add com.jakewharton to b4a ignore.

SLC will read the files from anwheresoftware.b4a.objects.*.java
it will find your wrapper java. It included the com.jakewharton code then. SLC will IGNORE them BUT put them into the resulting jar

Short: i would say you are on the right track
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
It is getting better. :)

I added the 3rd party java class to the same folder as my wrapper. All compiled fine with SLC and the compiled JAR was placed in my lib folder.
upload_2016-4-28_18-7-25.png



I then added to my project and received the error below when I tried to compile. Ideas?

upload_2016-4-28_18-15-38.png
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Yes, I do mean the additional lib folder. Sorry.
OK, here are the XML and JAR.

Thanks very much!!!!
 

Attachments

  • Phoenix.zip
    2.8 KB · Views: 254

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Yep, I had the dependson directive when I thought I had to compile the JAR by itself.
I removed it and I can build my app fine now. THANKS!!!!!!!!!!!!!!

I did run into this though when trying to invoke the lib. hhhhmmmm. But I wrapped and built it!!!!!


upload_2016-4-28_19-28-9.png
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
This is the XML for the sample they provide. I am thinking I might need to add something to my manifest?

B4X:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jakewharton.processphoenix.sample"
    >
  <application android:label="Process Phoenix">
    <activity android:name=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
        <category android:name="android.intent.category.DEFAULT"/>
      </intent-filter>
    </activity>
  </application>
</manifest>
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Where would that be? I looked in the folder I did the wrapping in but found nothing.
I did a search for *.xml (and sub folders) and still nothing?

Am I looking in the right place?
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Thanks for all your help @DonManfred I will attempt to wrap more libs in the future.

In the end I replaced it with.

B4X:
Dim r, r2 As Reflector
    r.Target = r.GetActivity
    r.Target = r.RunMethod("getApplicationContext")
    r2.Target = r.RunMethod("getPackageManager")
    Dim I As Intent = r2.RunMethod2("getLaunchIntentForPackage", r.RunMethod("getPackageName"), "java.lang.String" )
    r.Target = I
    r.RunMethod2("addFlags",  67108864, "java.lang.int")
    StartActivity(I)
 
Top