-
Notifications
You must be signed in to change notification settings - Fork 56
Hello World Android Studio
mlmateo edited this page Jan 27, 2016
·
1 revision
- File → New → New Project…
- Set these options through the wizard steps:
- Type a name for your application, your Company Domain and browse to the project location.
- Select the platforms and minimum SDK for your application (G3M requires API 15+)
- Select Empty Activity
- Name your activity and its layout
- Add G3M modules to your project. Open your settings.gradle file and add the lines starting with '+':
include ':app'
+include ':G3MSharedSDK'
+project(':G3MSharedSDK').projectDir = new File(settingsDir, '../relative/path/to/G3MSharedSDK')
+include ':G3MAndroidSDK'
+project(':G3MAndroidSDK').projectDir = new File(settingsDir, '../relative/path/to/G3MAndroidSDK')Tip: Alternatively, you may reference the location of G3M modules absolutely by typing:
include ':G3MSharedSDK'
project(':G3MSharedSDK').projectDir = new File('/absolute/path/to/G3MSharedSDK')Add some dependencies to your application module. Open your module’s build.gradle file and add:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
+ compile project(':G3MSharedSDK')
+ compile project(':G3MAndroidSDK')
}Tip: After these changes you should sync your project as the IDE suggests.
G3M widget can be added to any ViewGroup, so let’s add a FrameLayout as a place holder. Open the activity layout file (activity_main.xml), remove the lines starting with ‘-’ and add the following ones:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="mlmateo.helloworldandroidstudio.MainActivity">
- <TextView .../>
+ <FrameLayout
+ android:id="@+id/g3m_widget_holder"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
</RelativeLayout>Add the bold lines to the onCreate method of your MainActivity:
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+ final G3MBuilder_Android builder = new G3MBuilder_Android(this);
+ G3MWidget_Android g3mWidget = builder.createWidget();
+ final FrameLayout layout = (FrameLayout) findViewById(R.id.g3m_widget_holder);
+ layout.addView(g3mWidget);
}