Creating New Extension


#1

Hi Developers,
I am exploring creating extensions using App Inventor Sources. I have written my sample java file but on compile i have got error like this.

One quick question i have, in our java file whatever imports we are writing, are we supposed to include jars for the same??
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;


#2

There is no need to include the .jars for the common stuff.
In fact it would cause a Conflict since the .jar is already included and the .apk wouldn’t compile.


#3

3.3.1 Change your extension to have the desired package name

To make your extension have the desired package name, you need put its Java code in a directory tree whose subdirectories mirror the package name. This tree should sit under appinventor/components/src. For example, to make the Imageprocessor extension be in the package edu.mit.appinventor, you would go to the appinventor/components/src directory and in there create the treeedu/mit/appinventor. In more detail

  • go to the folder /appinventor/components/src, and in that folder
  • create a folder edu, and in that folder
  • create a folder mit, and in that folder
  • create a folder appinventor, and in that folder
  • put the file ImageProcessor.java

Learn More Here:
http://ai2.appinventor.mit.edu/reference/other/extensions.html


#4

See previous post and then add these imports.

import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.common.*; import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.runtime.util.*;


#5

Hi Ken,
Thanks for your valuable inputs. I have done what you have suggested. My java file is currently here:

C:\App Inventor\appinventor-sources\appinventor\components\src\com\meghraj\extensions

I have tried “ant extensions” again and saw some error again.

In case you would like to see my java file it:

package com.meghraj.extensions;

import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.common.
;
import com.google.appinventor.components.runtime.;
import com.google.appinventor.components.runtime.util.
;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

import android.os.Handler;

import android.util.Log;

import android.view.Surface;
import android.view.WindowManager;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

@DesignerComponent(version = YaVersion.LENGTH_UNIT_CONVERTER_VERSION,
description = “This is the extension to convert one length unit to other”,
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = “”)
@SimpleObject(external = true)
public class LengthConversion extends AndroidNonvisibleComponent implements Component {

public static final int VERSION=1;
@SimpleFunction(Description="this function will return number string")
public String FirstConverion(String str1) {
	if(str1.equalsIgnoreCase("1")) {
		return "one";
	}else if(str1.equalsIgnoreCase("2")) {
		return "two";
	}
}

}


#6

Check out my Calc.java, maybe it will help:


#7

Hi Kevin,
I just placed your file as it is within my package folder and changed package info in the file itself and then initiate the compilation. Again i got error


#8

Remove all SPACE characters from the path


#9

Yeah two things i have corrected.

  1. Removed any spaces from the path
  2. Added constructor to my class.

Works like a charm.

Thanks Ken for your quick responses. Really appreciate.