| |
Build and run the OpenFeint Sample Application
The sample app lets you experiment with the features you've configured on the OpenFeint dev dashboard before you've
begun to write your own app. Once you do begin working with your own app, it is frequently helpful to come back to the
sample app to compare how individual features work and how they are implemented.
- Build and run the OpenFeint Sample App for Android in Eclipse
NOTE: The following instructions assume you are using a standard installation of the Android SDK with the Eclipse IDE as described at http://developer.android.com/sdk/index.html. Adjustments may be required if your development environment is set up
differently. The "Hello World" sample app tutorial at http://developer.android.com/sdk/index.html is recommended as a good way to
test that your development environment is set up properly.
- Save the Contents of the OpenFeint Android SDK package in a convenient location.
Everything you need from this package to build the sample app is in the directory called
MyOpenFeintSample. You may copy this directory out of the package and rename it if you want to
use it as a starting point for experimental code.
- To develop in Eclipse:
- Open Eclipse with an empty workspace. This will present an empty "Project Explorer"
pane to which you will add a reference to the sample app project.
- Make sure that the path to your Android SDK has been set for this workspace. To set it, go to
Eclipse-->Preferences-->Android-->SDK Location.
- Add the sample app project to the workspace:
- Right click in the empty Project Explorer pane and select Import.
- Select General -->Existing Projects into Workspace from the import dialog.
- Click the Next button.
- Click Select root directory. Click Browse. Navigate to the MyOpenFeintSample directory in the OpenFeint package.
- Click Open.
- Click the Finish button.
- The MyOpenFeintSample is now listed in the project window.
Clicking the triangle next to MyOpenFeintSample should reveal an outline like this:
- Add your product information to the sample app:
- Bring up the OpenFeint developer dashboard (
https://api.openfeint.com/dd) in a browser. Choose the game you will use with the sample application. Click the Application Information button to show the
properties of the application you defined:
- In Eclipse, edit MyOpenFeintSample/src/com.openfeint.example/OpenFeintApplication.java;
construct your OpenFeint settings object using the game name, game ID, game key, and game secret of your game as
defined on the OpenFeint developer site:
- The values can be set in the class definition of the source code of your main activity:
static final String gameName = "Name of your application";
static final String gameID = "gameID";
static final String gameKey = "gameKey";
static final String gameSecret = "gameSecret";
For example, in the sample application, you could add these lines in
src/com.openfeint.example/OpenFeintApplication.java after:
public class OpenFeintExample extends ListActivity {
- Use the variables you defined to construct your settings object. This can be done in the
onCreate() method of your main activity:
OpenFeintSettings settings = new OpenFeintSettings(gameName, gameKey, gameSecret, gameID, options);
For example, in the sample application, you could add this line into the onCreate() method in
src/com.openfeint.example/OpenFeintApplication.java.
- Initialize OpenFeint. This is typically done in the onCreate() method of your main activity.
Add the the following line into the onCreate() method in your source code:
OpenFeint.initialize(this, settings, new OpenFeintDelegate() {});
For example, in the sample application, you could add this line into the onCreate() method in src/com.openfeint.example/OpenFeintApplication.java. Make sure you call OpenFeint.initialize()
after you've set the values in the settings object.
- Add the OpenFeint SDK project to the workspace:
- Right click in the empty Project Explorer pane and select Import.
- Select General -->Existing Projects into Workspace from the import dialog.
- Click the Next button.
- Click Select root directory. Click Browse. Navigate to the sdk directory in the OpenFeint package.
- Click Open.
- Click the Finish button.
- The OpenFeintAPI is now listed in the project window.
Clicking the triangle next to MyOpenFeintSample should reveal an outline like this:
- Try building the project to confirm that there are no build errors.
- If Project -->Build Automatically is checked, the project will try to rebuild
itself whenever its binaries are not up to date with its sources and
will likely be ready to run or debug on a connected device.
- If Project -->Build Automatically is not checked, you can manually request a build
with Project--> Build Project.
- If there are build errors, a mark appears over the project icon the list of errors appears
in the Markers pane:

- If you see an error that reads something like Project 'MyOpenFeintSample' is missing required
source folder: 'gen'" or if Eclipse cannot create R.java, add the gen/
directory to the Project.
- If you see a similar error for the OpenFeintAPI project, add the gen/ directory to the Project.
Note: Visit this list for solutions to some common build errors.
- Depending on your version of Eclipse and the Android tools, you may need to close the MyOpenFeintSample project and re-open it for it to correctly link to the OpenFeintAPI Android Library. The usual symptom for this is a java.lang.NoClassDefFoundError when trying to launch the sample application. If you experience this, right-click on the MyOpenFeintSample folder, select 'Close Project', then right-click on it again and select 'Open Project'. After rebuilding, the crash should be gone.
- Run the sample application on an Android device or simulator.
- You may use a USB cable to attach an Anrdoid device if configured for remote debugging or
allow the Android simulator to be used if no device is attached.
- Click the Run button or select Run from the Run menu.
- If the Run As dialog appears, select Android Application and click OK.

If successful, the sample app displays a list of OpenFeint features that you can test.
- Build and run the OpenFeint Sample App for Android in Ant
- Register an application using the OpenFeint developer dashboard at
https://api.openfeint.com/dd. There are step by step instructions here.
- Download the latest version of the OpenFeint SDK for Android.
- Extract the package.
-
Create a directory in which to build your sample application.
-
Copy the entire MyOpenFeintSample directory from the SDK download (It should be in the
download/OpenFeint.1.7.1 folder) into the new directory you created.
-
Open the MyOpenFeintSample/src/com/openfeint/example/OpenFeintApplication.java file and provide
your game's name, key, secret, and id to OpenFeintSettings. You can find these in the developer
dashboard at https://api.openfeint.com/dd.
- Copy the entire OpenFeintAPI directory from the download/OpenFeint.1.7.1 folder into
the root of the new directory.
- In a command window, change directories to the directory into which you placed the MyOpenFeintSample and the OpenFeintAPI.
- In the same command window, run:
android update lib-project -p OpenFeintAPI/ The following message appears:
Updated local.properties
Added file OpenFeintAPI/proguard.cfg
- Change your working directory to the location into which you copied the OpenFeint sample application:
cd dirContainingMyOpenFeintSample/MyOpenFeintSample
- In the same command window, run:
android update project -p
The following message appears:
Updated local.properties
Added file ././proguard.cfg
- Now enter:
ant debug
|