5.build extension

                                                                          

Tools you will need:

1.Git Bash(a software for download git code sources)

2.JDK(java 7)

3.a java code editor(Jedit,EditPlus,etc)

4.basic java programming experience

5.Apache ant(a software for complie extensions)

​​​2.Install apache ant(click to Download)

                                                                 HOW TO CREATE AN EXTENSION FOR APPINVENTOR2


Hi! I am Qiang, Wei,a high school student from China.I've made many extensions for appinventor2 which are shared in my homepage,but I would rather to share the process I made them.Sometimes, I am very busy in my school work, so I may not respond email immediately.I will respond you as soon as I can. I set up this website not for a long time,and I do very appreciate your support.

set environmental viables:

ANT_HOME to your install path


and add :

your install path of ant+"\bin" to "Path"

your install path of ant+"\lib" to "ClassPath"


after you install jdk,you need to set the environmental variables in your computer.

Please set "JAVA_HOME" to your install path.For instance,you can set "C:/Java/jdk1.7.0_79",which is a place where you install jdk.

Then,edit "PATH",add the following code in the front of the editor.

                                                    %JAVA_HOME%/bin;%JAVA_HOME%/jre/bin;

Finally,set "CLASSPATH" to

                                           .;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tools.jar

(these two file dt.jar and tools.jar are basic java class package for varies of functions.

-save the code we created before in the appinvenror sources file"/appinventor/components/src/com/"

-open up the XXX.sh

then it will start to compile the java file to an aix.

if it says "build successful",then you succeed in creating an extension.

Steps:

1.Install java 7 Devenlopment kit(click to Download)

3.Install Git bash(click to Download)

open Git bash:

type in "ant"

if says "build successful",you set it completely

if says "build faild",you may set something incorrecly

4.Start to create an extension

-Download the appinventor sources at github and decompress it.

-create a txt file and type in:

ant extensions

read

-Then,save it with name XXX.sh in /appinventor file


use the java code editor to establish a new file

-the first code you must add is the "package" line.

for example      

    package com.WeiWei.mail; //this is a pakage line,you can add a name for your file.


-after you write package code,you need to import external class.


code:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

package com.XX;


////////////////////////////////////////////LET'S START TO IMPORT FILE//////////////////////////////////////

import android.content.Context;      
import android.util.Log;  
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.runtime.collect.Sets;
import com.google.appinventor.components.runtime.util.BoundingBox;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.FileUtil;
import com.google.appinventor.components.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.util.PaintUtil;
import com.google.appinventor.components.common.ComponentConstants;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.common.YaVersion;


//the following file is the basic functional files for AppInventor.


3.Create a class and add annotations.


code:

//////////////////////////annotations for basic initialization////////////////////////////////////

@DesignerComponent(version = mail.VERSION,                           
    description = "",                                                        //this is your extension's description
    category = ComponentCategory.EXTENSION,     //the category is extension                          
    nonVisible = true,                                                        //only can be nonvisible        
    iconName = "XXX.jpg")                                              //picture path

@SimpleObject(external = true)     

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

public class XXX extends AndroidNonvisibleComponent    //set your class name in XXX for replacement.
implements Component {                                          
    public static final int VERSION = 0;                                          //version number
    private ComponentContainer container;                               //define the component
    private Context context;                                                            //define the context
    private static final String LOG_TAG = "mail";                      //modify "mail" to your extension name
    public mail(ComponentContainer container) {         
        super(container.$form());                                
        this.container = container;                              
        context = (Context) container.$context();                      //define the context         
        Log.d(LOG_TAG, "mail Created" );                                 //record
    }

////////////////////////////////////////////add your code here//////////////////////////////////////////////////////////

///////////////////choose one or both of the following way//////////////////////////////////////////////////////////////

@SimpleFunction(description = "")//annotation you must add in order to appear in appinventor as a function

public int plus(int a,int b)

{

return a+b;

}


@SimpleProperty(description = "")//annotations you must add in order to appear in appinventor as an setable characteristics

public boolean abc(int a,int b)

{

if (a ==b){

return ture;

                }else

{return false;}

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

}