Install Parse SDK on your Android Studio Project
Introduction
In this section you learn how to install Parse Android SDK into your Android Studio project.
This tutorial uses a basic app created in Android Studio 3.2 with Compile SDK Version = 27 and targetSdkVersion 27
At any time, you can access the complete Android Project built with this tutorial at our GitHub repository.
Prerequisites
To complete this tutorial, you need:
- An app created at Back4App.
- Note: Follow the New Parse App tutorial to learn how to create a Parse app at Back4App.
- Android Studio.
- Basic android app.
- Note: If you don’t have a basic app created you can follow the Create a Project tutorial from Android Studio Website. After you create your basic app you are ready to follow this guide.
Note: Parse Android SDK works with Compile SDK Version = 27 and targetSdkVersion 27 or higher.
Step 1 - Install SDK
Android Studio uses Gradle (an advanced build toolkit) to automate and manage the build process while allowing you to define flexible custom build configurations. To install Parse SDK for Android you will have to make some set up in the Gradle of your Android Studio Project. To do so, follow the steps described below:
- In your Android Studio project, open your
build.gradle (Module:app)
file.Be careful, there are two files named
build.gradle
. You want to modify the(Module:app)
one. - Now, go right after the
dependencies{}
tag in thebuild.gradle (Module:app)
file and copy the following code snippet:1 2 3 4 5
repositories { mavenCentral() jcenter() maven { url 'https://jitpack.io' } }
- It’s also necessary to look in the
android{}
tag if yourcompileSdkVersion
is 27 or higher and also if yourtargetSdkVersion
is 27 or higher. If they aren’t, you must change these versions to 27 or higher, otherwise your Parse SDK for Android may not work properly. After checking this, yourbuild.gradle (Module:app)
should look like the one in the image below. - Now you are ready to install the Parse SDK. To do so, you need to add the following lines inside the
dependencies{}
tag.1 2
// Don't forget to change the line below with the latest version of Parse SDK for Android implementation "com.github.parse-community.Parse-SDK-Android:parse:latest.version.here"
Remember to update the version of Parse SDK for Android to the latest one. You can find out which is the latest version at JitPack website, following these steps:
- At JitPack website paste
parse-community/Parse-SDK-Android
in theGit repo url
box. - After doing that, click on the
Look up
button. Then you should see the available versions of Parse SDK for Android, as shown in the following image.
- At JitPack website paste
- Sync your
build.gradle
and we are ready to go.
To learn more about adding support libraries to your Android Studio Project, see the Android Studio’s Support Library Setup page.
Step 2 - Connect your app to Back4App
To use the Parse SDK, your application need to have access to the internet network. To allow your app to have it, you need to grant permissions in the AndroidManifest.xml
file. Also, you have to set up the app’s credentials to connect your app to Back4App. To do this, folow the steps below.
- Go to
app
>manifests
>AndroidManifest.xml
in your Android Studio Project. - Now, go right after the
application
tag in theAndroidManifest.xml
file and copy the following code snippet:1 2
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET"/>
- Inside the
application
section of theAndroidManifest.xml
file, add the following code:1 2 3 4 5 6 7 8 9
<meta-data android:name="com.parse.SERVER_URL" android:value="@string/back4app_server_url" /> <meta-data android:name="com.parse.APPLICATION_ID" android:value="@string/back4app_app_id" /> <meta-data android:name="com.parse.CLIENT_KEY" android:value="@string/back4app_client_key" />
- Go to
app
>res
>values
>strings.xml
file. - In the
strings.xml
file add the following code:1 2 3 4 5
<string name="back4app_server_url">https://parseapi.back4app.com/</string> <!-- Change the following strings as required --> <string name="back4app_app_id">PASTE_YOUR_APPLICATION_ID_HERE</string> <string name="back4app_client_key">PASTE_YOUR_CLIENT_KEY_HERE</string>
- Leave the
string.xml
opened and go to Back4App Website, log in and click onMy Apps
. Find your app and then click onSERVER SETTINGS
. - Find the “Core Settings” block and click on
Settings
. The “Core Settings” block looks like this: - After that, you will see the details of your Parse app, such as your
App Id
and yourClient Key
. Copy these credentials and paste them in the appropriate place at thestrings.xml
file of your Android Studio Project.
Step 3 - Initialize your Parse App
- Create a Java file called
App
that extends Application. - Import to your
App.java
file:1
import com.parse.Parse;
- Inside App.java
onCreate
method, right aftersuper.onCreate()
call the following code:1 2 3 4 5 6 7
Parse.initialize(new Parse.Configuration.Builder(this) .applicationId(getString(R.string.back4app_app_id)) // if defined .clientKey(getString(R.string.back4app_client_key)) .server(getString(R.string.back4app_server_url)) .build() );
Don’t forget to define this file in the
AndroidManifest.xml
. To do so, go to theAndroidManifest.xml
file and add the following line of code inside theapplication
tag:1
android:name=".App"
If the name of the java file that extends Application that you created on the previous step isn’t “App”, don’t forget that the code above should have the correct name of the file (
android:name=".name_of_the_file"
).
Step 4 - Test your connection
With Parse SDK every time a user download your app, it’s possible to register its installation by using the ParseInstallation.getCurrentInstallation()
method of ParseInstallation
class. The first time you save a ParseInstallation
, Parse will add it to your Installation
class on your Dashboard. To test your connection with Parse SDK, let’s save an installation in the main activity of your Android Studio Project, following the steps described below.
- Go to your Android Studio Project and add the following code to your
onCreate()
method in order to save the installation of the application into your Dashboard.1 2
// Save the current Installation to Back4App ParseInstallation.getCurrentInstallation().saveInBackground();
- Launch your app and go to Back4App Website and click on
My Apps
. Find your app and then click onDASHBOARD
. - Now click on
Core
>Browser
>Installation
. You should see an installation registered, as shown in the image below.
It’s done!
At this point, you have learned how to install the Parse SDK in your application.
Learn more by walking around our Android Tutorials.