Creating an Android Project with Forcedroid
- Specify the type of application you want, along with basic configuration
data.
OR
- Use an existing Mobile SDK app as a template. You still provide the basic configuration data.
Forcedroid Project Types
| App Type | Architecture | Language |
|---|---|---|
| native | Native | Java |
| native_kotlin (or just press RETURN) | Native | Kotlin |
To develop a native Android app in Java, specify native.
Using forcedroid create Interactively
1$ forcedroid create
2Enter your application type (native, native_kotlin): <press RETURN>
3Enter your application name: testNative
4Enter the package name for your app (com.mycompany.myapp): com.bestapps.android
5Enter your organization name (Acme, Inc.): BestApps
6Enter output directory for your app (leave empty for the current directory): testNativeUsing forcedroid create in Script Mode
In script mode, you can use forcedroid without interactive prompts. For example, to create a native app written in Java:
1$ forcedroid create --apptype="native" --appname="package-test" --packagename="com.acme.mobile_apps"
2 --organization="Acme Widgets, Inc." --outputdir="PackageTest"1$ forcedroid create --apptype="native_kotlin" --appname="package-test" --packagename="com.acme.mobile_apps"
2 --organization="Acme Widgets, Inc." --outputdir="PackageTest"Each of these calls creates a native app named “package-test” and places it in the PackageTest/ subdirectory of your current directory.
Creating an App from a Template
The forcedroid createWithTemplate command is identical to forcedroid create except that it asks for a GitHub repo URI instead of an app type. You set this URI to point to any repo directory that contains a Mobile SDK app that can be used as a template. Your template app can be any supported Mobile SDK app type. The script changes the template’s identifiers and configuration to match the values you provide for the other parameters.
1Available templates:
2
31) Basic Kotlin application
4forcedroid createwithtemplate --templaterepouri=AndroidNativeKotlinTemplate
52) Basic Java application
6forcedroid createwithtemplate --templaterepouri=AndroidNativeTemplate
73) Sample Kotlin Identity Provider application
8forcedroid createwithtemplate --templaterepouri=AndroidIDPTemplate1Usage:
2forcedroid createWithTemplate
3 --templaterepouri=<Template repo URI> (e.g. https://github.com/forcedotcom/SalesforceMobileSDK-Templates/MobileSyncExplorerReactNative)]
4 --appname=<Application Name>
5 --packagename=<App Package Identifier> (e.g. com.mycompany.myapp)
6 --organization=<Organization Name> (Your company's/organization's name)
7 --outputdir=<Output directory> (Leave empty for current directory)]1forcedroid createwithtemplate --templaterepouri=AndroidNativeKotlinTemplateYou can use forcedroid createWithTemplate interactively or in script mode. For example, here’s a script mode call:
1forcedroid createWithTemplate
2--templaterepouri=SalesforceMobileSDK-Templates/AndroidIDPTemplate#v6.2.0
3--appname=MyIDP-Android
4-—packagename=com.mycompany.react
5--organization="Acme Software, Inc."
6-—outputdir=testWithTemplateChecking the Forcedroid Version
1forcedroid versionImport and Build Your App in Android Studio
-
Open the project in Android Studio.
-
From the Welcome screen, click Import Project (Eclipse ADT, Gradle, etc.).
OR
-
From the File menu, click .
-
-
Browse to your project directory and click OK.
Android Studio automatically builds your workspace. This process can take several minutes. When the status bar reports “Gradle build successful”, you’re ready to run the project.
-
Click Run
<project_name>, or press SHIFT+F10. For native
projects, the project name is the app name that you specified.
Android Studio launches your app in the emulator or on your connected Android device.
Building and Running Your App from the Command Line
After the command-line returns to the command prompt, the forcedroid script prints instructions for running Android utilities to configure and clean your project. Follow these instructions if you want to build and run your app from the command line.
- Build the new application.
-
Windows:
1cd <your_project_directory> 2gradlew assembleDebug -
Mac:
1cd <your_project_directory> 2./gradlew assembleDebug
When the build completes successfully, you can find your signed APK debug file in the project’s build/outputs/apk directory.
-
- If you’re using an emulator that isn’t running, use the Android AVD Manager to start it. If you’re using a physical device, connect it.
- Install the APK file on the emulator or device.
-
Windows:
1adb install <path_to_your_app>\build\outputs\apk\<app_name>.apk -
Mac:
1./adb install <path_to_your_app>/build/outputs/apk/<app_name>.apk
-
Windows:
If you can’t find your newly installed app, try restarting your emulator or device. For more information, search “Build your app from the command line” at developer.android.com.
How the Forcedroid Script Generates New Apps
- The script downloads templates at runtime from a GitHub repo.
- The forcedroid create command uses the default Kotlin template in the SalesforceMobileSDK-Templates GitHub repo.
- Generated apps use Gradle.
- The script uses npm at runtime to download Mobile SDK libraries. The settings.gradle file points to these libraries under node_modules.