How include external .jar libraries to extensions?

698 views
Skip to first unread message

Uriel Albarran Oropeza

unread,
Mar 7, 2018, 6:31:26 PM3/7/18
to App Inventor Open Source Development
I'm creating an extension just to know how they're build, and have this question: How I can Include external SDKs on my extensions? many on them tell you to download a .jar file and include it on your libs folder (This is just for Android Studio) and add the lines: import com.sdksite.company.package so I really don't know what to do with that, any help from the masters on Extensions?

Taifun

unread,
Mar 7, 2018, 7:17:57 PM3/7/18
to App Inventor Open Source Development
see the App Inventor Extensions document chapter 3.2.3 and follow the link mentioned there

Taifun

Uriel Albarran Oropeza

unread,
Mar 7, 2018, 9:09:33 PM3/7/18
to App Inventor Open Source Development
Thanks that works, but I'm still stuck with the import com.domain.package part because If I include those lines give me an error it say "package does not exist", I'm trying to create an extension for this: http://docs.superrewards.com/docs/getting-started-android

I have plans on create some Extensions for monetize apps and give the .aix for free on the forums, this because I don't find any extensions like this and looks like can be really useful for everyone.

Jose Dominguez

unread,
Mar 8, 2018, 5:03:39 AM3/8/18
to app-inventor-open-source-dev
Can you list the actual imports that don't work?
It is possible that their SDK depends on something like the android
support libraries that are not included in the master branch (I
think). I seem to recall the support libraries are part of the ucr
branch?

cheers,
José
> --
> You received this message because you are subscribed to the Google Groups
> "App Inventor Open Source Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to app-inventor-open-so...@googlegroups.com.
> To post to this group, send email to
> app-inventor-o...@googlegroups.com.
> Visit this group at
> https://groups.google.com/group/app-inventor-open-source-dev.
> For more options, visit https://groups.google.com/d/optout.

Uriel Albarran Oropeza

unread,
Mar 8, 2018, 5:19:20 PM3/8/18
to App Inventor Open Source Development
According with me I have error importing this:

import com.playerize.superrewards.SuperRewards;
import com.playerize.superrewards.SRUserPoints;

I add to my 3 build.xml files:

appinventor/build.xml:  <pathelement location="lib/superRewards/SuperRewards-3.1b.jar" />
appinventor/buildserver/build.xml:  <copy toFile="${classes.files.dir}/sprRewards.jar" file="${lib.dir}/superRewards/SuperRewards-3.1b.jar" />
appinventor/components/build.xml: <pathelement location="${lib.dir}/superRewards/SuperRewards-3.1b.jar" />

Also I add this to my java Extension:

import com.google.appinventor.components.annotations.UsesLibraries;
import com.google.appinventor.components.annotations.UsesPermissions;

After that:

@UsesPermissions(permissionNames =
    "android.permission.INTERNET," +
    "android.permission.ACCESS_NETWORK_STATE," +
    "android.permission.READ_PHONE_STATE")
@SimpleObject(external = true)
@UsesLibraries(libraries = "sprRewards.jar")

Also I upload the .jar file to:

appinventor/lib/superRewards/SuperRewards-3.1b.jar

If I don't include the lines:

import com.playerize.superrewards.SuperRewards;
import com.playerize.superrewards.SRUserPoints;

I build the extension without problems, also I'm not so sure how I'm going to invoke the offer wall XD.
Like I say I'm new on this and I'm experimenting, but is really complicated find tutorials or help to resolve my doubts.

Jose Dominguez

unread,
Mar 9, 2018, 4:15:24 AM3/9/18
to app-inventor-open-source-dev
I can't recall which one, but one of the build files needs the jar
added twice; check that one out and let us know if you can get it to
work.

cheers,
José

Andres Cotes

unread,
Mar 9, 2018, 10:09:09 AM3/9/18
to App Inventor Open Source Development
appinventor/components/build.xml: <pathelement location="${lib.dir}/superRewards/SuperRewards-3.1b.jar" />

 you must add this line 2 times in the same file search for tweet and guide you in the 2 places you should put it

Andres Cotes

unread,
Mar 9, 2018, 10:17:59 AM3/9/18
to App Inventor Open Source Development
the extension you want to build will only work in a built apk, or you must compile the extension and create your own companion you must follow the read barcode passages to be able to create that extension

Uriel Albarran Oropeza

unread,
Mar 9, 2018, 1:36:26 PM3/9/18
to App Inventor Open Source Development
That solve the import issue, thanks. I forgot to add that line to /build.xmlai.apt macro definition

Uriel Albarran Oropeza

unread,
Mar 9, 2018, 2:56:18 PM3/9/18
to App Inventor Open Source Development
I have this: but I think i'm wrong:

package com.superRewards;
//  © Uriel Albarran Oropeza
// Extension to call superrewards offerwall.

import com.playerize.superrewards.SuperRewards;
import com.playerize.superrewards.SRUserPoints;

import com.google.appinventor.components.annotations.UsesLibraries;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.*;

@DesignerComponent(version = superRewards.VERSION,
    description = "SuperRewards. " + "\nIntegration Extension",
    category = ComponentCategory.EXTENSION,
    nonVisible = true,
@UsesPermissions(permissionNames =
    "android.permission.INTERNET," +
    "android.permission.ACCESS_NETWORK_STATE," +
    "android.permission.READ_PHONE_STATE")
@SimpleObject(external = true)
@UsesLibraries(libraries = "superRewards.jar")
public class superRewards extends AndroidNonvisibleComponent implements Component {

    public static final int VERSION = 1;
    
    public static final String USER_ID = "9001234";
public static final String APP_HASH = "nhhpuxlrfgi.022815956434";
    private ComponentContainer container;
    
    private String user_id = "";
private String app_hash = "";
 
    public superRewards(ComponentContainer container) {
        super(container.$form());
        this.container = container;
        userID(USER_ID);
appHash(APP_HASH);
    }

    // Creacion de las Propiedades.
    @SimpleProperty(
        category = PropertyCategory.BEHAVIOR)
    public String userID() {
        return user_id;
    }
@SimpleProperty(
        category = PropertyCategory.BEHAVIOR)
public String appHash() {
        return app_hash;
    }

    // Establecimiento de las Propiedades.
    @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = superRewards.USER_ID + "")
    @SimpleProperty(description = "User ID on your database. It can be either numeric or text, but must be passed as a String variable")
    public void userID(String nuevouserID) {
        this.user_id = nuevouserID;
    }
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = superRewards.APP_HASH + "")
    @SimpleProperty(description = "Your app hash, which you can find in your Dashboard.")
    public void appHash(String nuevoappHash) {
        this.app_hash = nuevoappHash;
    }

    // Funcion que une los dos textos.
    @SimpleFunction(description = "Join both variables to call the Offers.")
    public String superRewards(String userID, String appHash) {
        SuperRewards sr = new SuperRewards(getResources(), "com.play.Getcogas");
sr.showOffers(MainActivity.this, appHash, userID);
    }
}


I have this error as result:


Andres Cotes

unread,
Mar 9, 2018, 3:03:04 PM3/9/18
to App Inventor Open Source Development
private Activity  currentActivity;



currentActivity  = (Activity) context;


remplace Mainactivity.this for currentActivity:


no posible call element resource


currentActivity.getResources();

Uriel Albarran Oropeza

unread,
Mar 9, 2018, 3:24:04 PM3/9/18
to App Inventor Open Source Development
Done this:

package com.superRewards;
//  © Uriel Albarran Oropeza
// Extension to call superrewards offerwall.

import com.playerize.superrewards.SuperRewards;
import com.playerize.superrewards.SRUserPoints;

import com.google.appinventor.components.annotations.UsesActivities;
import com.google.appinventor.components.annotations.UsesLibraries;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.*;

@DesignerComponent(version = superRewards.VERSION,
    description = "SuperRewards. " + "\nIntegration Extension",
    category = ComponentCategory.EXTENSION,
    nonVisible = true,
@UsesPermissions(permissionNames =
    "android.permission.INTERNET," +
    "android.permission.ACCESS_NETWORK_STATE," +
    "android.permission.READ_PHONE_STATE")
@SimpleObject(external = true)
@UsesActivities(activities = {
@ActivityElement(name = "com.playerize.superrewards.activities.SRWebViewActivity",
screenOrientation = "portrait")
})
@UsesLibraries(libraries = "superRewards.jar")
public class superRewards extends AndroidNonvisibleComponent implements Component {

    public static final int VERSION = 1;
    
    public static final String USER_ID = "9001234";
public static final String APP_HASH = "nhhpuxlrfgi.022815956434";
    private ComponentContainer container;
    private Activity  currentActivity;
        SuperRewards sr = new SuperRewards(currentActivity.getResources(), "com.playerize.awesomeapp");
        currentActivity = (Activity) context;
sr.showOffers(currentActivity, appHash, userID);
    }
}

Now I have this:


Sorry for keep asking, like I say before, I'm still learning


Andres Cotes

unread,
Mar 9, 2018, 3:31:56 PM3/9/18
to App Inventor Open Source Development
mi whatsapp + 57 3177959176
Reply all
Reply to author
Forward
0 new messages