The rest2mobile Android Studio plugin allows you to generate mobile api from REST services directly inside your android project. You can check out this short demo to see how it works.
- [1.1.12] (https://github.com/magnetsystems/r2m-plugin-android/releases/1.1.12)
- fixed issue #31
- fixed issue #29
- refactoring
- "Close wizard" window stays in the foreground
- UI Cosmetics
- Lazily create .rest2mobile
- fix for magnetsystems#23
- fix for magnetsystems#22
- fix for magnetsystems#4
- 1.1.7
- fix for magnetsystems#27
- fix for magnetsystems/r2m-sdk-android#5 (from 1.1.6 pre-release)
- 1.1.5
- fix for magnetsystems/r2m-sdk-android#4
- 1.1.4
- 1.1.0
- 1.0.0
The latest stable release is also published on the Jetbrains plugin repository
The rest2mobile plugin for Android Studio & IntelliJ IDEA has these prerequisites:
- Java JDK 1.6 or later
- Android Studio or IntelliJ IDEA
- Android 'minSDKVersion' value of 15 or later
Use IntelliJ 13 or later to create the plugin project from the source:
- create the project from the source directory
src
- register the
res
andl10n
directories as resources - register the
libs
directory as a library
Build the plugin zip using the Build->Prepare Plugin Module ... for deployment
option.
The installation instructions are summarized here.
Be sure you include the rest2mobile Android SDK in your app by inserting this in your app's build.gradle
by adding the following lines to it:
repositories {
maven {
url "http://repo.magnet.com:8081/artifactory/public/"
}
mavenLocal()
mavenCentral()
}
dependencies {
compile("com.magnet:r2m-sdk-android:1.1.0@aar") {
transitive = true
}
}
STEP 1: Download
Go to the releases and download the latest installer.
Note: You can find the latest official release on the Magnet developer site too.
STEP 2: Install plugin
In Android Studio or IntelliJ, go to Preferences -> Plugins
and click on Install plugin from disk...
It will ask you to choose the location of the installer zip, point to the package that you've just downloaded.
Note: the plugin is also distributed on the Jetbrains repository, so instead of clicking on Install plugin from disk...
, you can choose Browse repositories...
and then look for rest2mobile
.
STEP 3: Restart your IDE after loading the plugin
STEP 4: Load or create an android application
It is recommended to use a gradle-based application (if you are still using ant, go here).
Ensure that you use at a minimum the Android API level 15.
STEP 5: Add new API
Once the IDE has restarted, you should see the new R2M menu (or "Magnet" menu in earlier releases):
Choose "Add new API" from the R2M menu ('Magnet' menu for earlier releases). The following describes the wizard options:
Alternatively, instead of crafting your own REST invocations, you can load existing examples from the r2m-examples github repo by clicking on the browse icon next to the Class Name
box:
STEP 6: Generate code
Click on "Generate", this generates the code under your src
directory. If you have a src/androidTest/java
directory, a unit test file is also generated.
Ex: say you selected the GoogleDistance
built-in example, you should see the following files in your project pane:
STEP 7: Test
Use the generated unit test generated under src/androidtest/java/
Ex: if you generated the GoogleDistance
native API, the unit test can be found atr src/androidTest/java/com/magnetapi/examples/controller/api/test/GoogleDistanceTest
. Remove the @Supress
annotation on testGoogleDistance
, and invoke the API with real values:
/**
* Generated unit test for {@link GoogleDistance#googleDistance}
*/
@SmallTest
public void testGoogleDistance() throws SchemaException, ExecutionException, InterruptedException {
String origins = "435 Tasso Street, Palo Alto CA";
String destinations = "1 Embarcadero Street, San Francisco, CA";
String sensor = "false";
String mode = "driving";
String language = "en";
String units = "imperial";
Call<GoogleDistanceResult> callObject = googleDistance.googleDistance(
origins,
destinations,
sensor,
mode,
language,
units, null);
GoogleDistanceResult result = callObject.get(); // Or use a non-null 'StateChangedListener' in 'googleDistance' to be asynchronously called back, once result is avail.
assertEquals("33.9 mi", result.getRows().get(0).getElements().get(0).getDistance().getText());// actual distance may vary
}
Notice how the rest2mobile's java invocation allows you to safely navigate the JSON payload:
Strongly-typed in java:
String distance = result.getRows().get(0).getElements().get(0).getDistance().getText());
Stringly-typed in JSON:
{
"destination_addresses" : [ "1 Lombard Street, San Francisco, CA 94111, USA" ],
"origin_addresses" : [ "435 Tasso Street, Palo Alto, CA 94301, USA" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "33.9 mi",
"value" : 54605
},
"duration" : {
"text" : "44 mins",
"value" : 2626
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
We are constantly adding features and welcome feedback. Please, ask questions or file requests here.
Get latest tips, news, and useful information from our blog
Licensed under the [Apache License, Version 2.0] license (the "License"); you may not use this software except in compliance with the License.
Copyright © 2014-2015 Magnet Systems, Inc. All rights reserved.