для чего нужен sap btp sdk for android
Installing the SAP BTP SDK for Android¶
Extract the contents of the SAP BTP SDK for Android software download file to a folder on your computer and run the installation script. The installation script copies the SDK libraries to the local Maven repository and installs the Android Studio plugin.
If you reset or lose your local maven repository, re-run the install script to ensure the SDK libraries are copied to your new local Maven repository.
If you need to uninstall the Wizard plugin, run the uninstall_wizard script in the same directory.
Requirements¶
You’ll require Android Studio 4.0.x, 4.1.x or 4.2.x installed on your computer. Download Android Studio here.
Android Studio includes the latest Android SDK. We recommend you use the Android SDK Manager to keep the Android SDK up to date. Refer to your Android Studio documentation for details on using this tool.
Procedure¶
Run the installation script at the root of the extracted zip. The script installs the Android Wizard plugin in Android Studio and copies the SDK libraries to your local Maven repository.
Do not delete or move the folder where you extracted the program files. SDK tools are installed in this directory and are accessed from this location.
(Recommended) Set the SAP_ANDROID_HOME environment variable to point to your installation folder.
Configuring the Wizard Plugin¶
When you install the SDK, the installation script copies the SDK libraries to the local Maven repository.
If required, you can specify a different Maven repository for the wizard to use when generating a new app. For example, if you select the Use SAP Cloud Shipment option, the wizard will use the URL of the SAP Cloud Shipment channel, which is a public customer-facing SAP Maven repository; if you select the Use other repository option, you can provide the network path or URL of a remote server. This allows all the developers on your team to use the same, central version of the SDK without any additional manual downloads.
In the left panel, select SAP BTP SDK for Android. In this configuration page, there are three options provided:
The credentials of the technical user need to be regenerated every 6 months.
Try Out the SAP BTP SDK Wizard for Android
You will learn
Prerequisites
Please read Prerequisites first.
Open Android Studio.
Choose Start a new SAP Business Technology Platform Android project, which is an option created by the SAP BTP SDK Wizard for Android.
The wizard can save the server connection details for multiple servers. Fill in the required fields as shown below.
Field | Value |
---|---|
Account Name | SAP Mobile Services |
Admin API URL | See below for how to get this URL |
Admin UI URL | See below for how to get this URL |
Authentication Type | Basic |
Username | Username for your account |
Password | Password for your account |
Save Account Information | Check this so that you do not have to re-enter account information on subsequent runs of the wizard |
Go to the SAP Mobile Services cockpit and under Important Links, both Admin URLs are present and can be copied.
Click Next on the Server Connection tab.
SAP Mobile Services provides a sample back-end destination named com.sap.edm.sampleservice.v2 that is being used here to provide data for the application. It contains product categories, product, supplier, customer and sales order data. Select it and click Next.
On the Android Studio Project tab, provide the following configuration data.
Field | Value |
---|---|
Project Name | Wiz App |
Project Namespace | com.sap.wizapp |
Target Language | Java / Kotlin |
The screenshot below provides a Java example. Depending on which Target Language you choose, either Java or Kotlin code will be generated.
On the Project Features tab, provide the following configuration data.
Introduction¶
flows2 provides a default implementation for your app’s onboarding and restoring scenarios. It handles all the necessary steps during onboarding: getting the application configuration from either the Discovery Service or by scanning a QR code, authenticating users based on the application configuration, and creating and validating passcodes, for example. These scenarios are based on the existing Foundation and Fiori libraries.
Besides the default implementation, there are also extension points that allow client code to provide its own logic, for example providing additional passcode validation rules, encrypting a local business data secure store with the passcode, etc.
At the same time, all the customization options of the UI are still supported, and additional custom code can be added to flows as well. The flows execute the onboarding and restoring scenarios as a sequential step sequence. Custom code can be added using custom steps added by the app developer.
Multiple user support was added in the SAP BTP SDK for Android 3.3. Now, the single code base flow can support both single and multiple user mode.
Installation¶
To use the flows component, include the following dependency in your build.gradle.
Flow Types¶
The Flows library currently supports the following scenarios (flow types) for onboarding flows implementation, described below:
Each flow contains several steps and each step can be either a single step or a nested flow that contains other steps. For example, the activation step inside the onboarding flow is a nested flow: it contains the step to get application configuration from the Discovery Service and the QR scanning step. Step organization makes it easier to extend the flows component.
The ‘Forgot Passcode’ and ‘Create New Account’ flows are actually the same as the ‘Onboard’ flow, but with different constraints. The ‘Forgot Passcode’ flow requires the user ID context to identify which user forgot their passcode. The ‘Create New Account’ flow is used in multiple user mode when creating a new account.
Besides these predefined flows, you can also use the flows component as a framework to create customized flows, as described below.
The Onboard Scenario¶
The onboarding flow contains the following steps:
The Restore Scenario¶
After onboarding, the next time the mobile application starts it will execute the restore scenario. The restore flow will first unlock the application with either the passcode or fingerprint, if enabled. Then, if the passcode has expired, the change passcode flow is executed.
The flows component will automatically determine whether to use onboarding or restore, so the client code can use the same source code for these two flows.
The Change Passcode Scenario¶
After onboarding, if the user wants to change the current passcode, the change passcode flow can be started. This flow contains three steps: unlock with passcode, set a new passcode, and confirm the new passcode. This flow will also automatically be executed as part of the restore flow if the current passcode has expired.
The Reset Client Scenario¶
There will be cases when the user wants to reset the mobile client, for example if they have forgotten their passcode. When resetting the client, besides the internal status of the flows component, the client might also have something to clear. And after reset the client mobile application might also want to open the launcher screen, so besides calling the flow component for reset, the client mobile application should also have a FlowStateListener defined and provided to the reset flow.
Introduction¶
SAP Mobile Services is a cloud-based offering that is complemented by various development tools such as the native SDKs for iOS, Android, the mobile development kit or SAP Mobile Cards.
The overall objective is to deliver reusable services, which can be leveraged in mobile app development projects, to ensure that app developers can concentrate on delivering their business requirements rather than repeatedly building infrastructure features for every mobile project.
Using SAP Business Technology Platform can be a robust foundation to base an enterprise-wide mobile strategy on, reducing time-to-market for both in-house and consumer-facing mobile solutions.
With a mobile strategy in place, development teams can rely on best practices and significantly increase their productivity, resulting in robust and secure apps and reduced delivery times.
Maintenance of such solutions is streamlined using features that make troubleshooting easier.
The overall picture of the solution could look something like this:
The Challenge¶
Mobile application development is a challenging task as these projects place a high demand on user experience, fast delivery cycles, and device platform diversity. At the same time, projects often suffer from a lack of expertise and missing skills in the team.
Considerations such as the time-to-market, and requirements such as push notifications and support for offline data access, are common complexity drivers for mobile apps. As businesses demand greater presence in not only the traditional desktop environment but also mobile environments, the maintenance of code and applications becomes a real factor in the cost of operations.
To manage all these expectations and requirements it is important to execute mobile app development projects on a common foundation. This includes setting up a governance process for the app development teams in the first place. Such a process or strategy should contain a guide to answer questions like:
This is not a complete list, but rather a good indication of the thought processes leading to the formulation of a mobile strategy.
The Solution¶
SAP Mobile Services has such a strategy, and is also beneficial for executing the strategy by providing reuse services, compliance features, optimal development options for each use case, and more.
Here’s another view on SAP Mobile Services:
The boxes at the bottom depict the various reuse components that help to free application developers from tedious tasks when implementing strategy-compliant features. The top of the diagram shows the development options that can be chosen from to implement a business case in the most optimal way. These development options consume the features and functions that are provided by SAP Mobile Services in a standardized manner. Using this concept, mobile app developers can concentrate on their important tasks and are freed from tedious, repetitive tasks, such as implementing authentication.
The benefits of centralized mobile app management become increasingly apparent the more apps you manage with SAP Mobile Services.
Surrounding Tools¶
This documentation describes all of these features and functions and how to use them properly.
Creating Apps From Scratch¶
If you decide not to use the Wizard, you can still create a new Android Studio project and then build an app using the SDK libraries, or add the SDK to an existing project. To do this, you’ll need to modify the top-level and module-level build.gradle files manually to include all required repositories, dependencies, and settings.
The top-level file stores configuration options common to all sub-projects/modules. The module-level file stores options for your new app.
To generate proxy class Java files, use either the OData Gradle Plugin or the Proxy Generator CLI tool. Both tools are included in the software package.
To use the OData Gradle Plugin, modify the two build.gradle files to add the plugin as a dependency and configure it as required. To use the Proxy Generator CLI tool, open a command prompt and enter the required command. See Using the OData Proxy Class Generator Command-line Tool for more information.
Prerequisites¶
You have run the installation script to install the SDK. See Installing the SAP BTP SDK for Android for more information.
Procedure¶
From the project tool window, navigate to the appropriate folder and open the build.gradle file in the editor window.
Add the required dependencies to the project
Adding Required Repositories to Your Project¶
Add all required repositories including the local Maven repository to your project by modifying the app module build.gradle file for your project.
From Android Studio, open the top-level build.gradle file and add the following to all the repositories blocks:
Now all Android projects will also fetch dependencies from SAP infrastructure.
You can add the above Maven project to your project repositories in the app module build.gradle file, the above settings can be maintained on the project level.
Adding Project Dependencies¶
Add one or more of the SDK for Android components as required for your mobile application. The SDK includes the following libraries:
Library | Gradle Dependency Line |
---|---|
Fiori | com.sap.cloud.android:fiori:3.4.0 |
Foundation | com.sap.cloud.android:foundation:3.4.0 |
OData | com.sap.cloud.android:odata:3.4.0 |
Offline OData | com.sap.cloud.android:offline-odata:3.4.0 |
Onboarding | com.sap.cloud.android:onboarding:3.4.0 |
Flows | com.sap.cloud.android:flowsv2:3.4.0 |
Google Vision | com.sap.cloud.android:google-vision:3.4.0 |
Add the following SDK libraries as dependencies to your module-level build.gradle file:
If you intend to enable logging, include logback-android dependencies to this enclosure:
Update the target SDK version and compatibility versions as follows to your module-level build.gradle file:
Initializing SDK¶
Since there are many modules in the Foundation component, using them in the client code to integrate your application with SAP Mobile Services will require lots of boilerplate code in the mobile application. To reduce the boilerplate code from your mobile application, a new API SDKInitializer.start is introduced as below:
The parameters are explained below:
This parameter represents the running Android app.
This parameter represents all the services to be initialized in your application. Currently the following services are supported:
This parameter takes a service object, which contains configuration properties for most of the services, as the value. For example, the UsageService can configure auto session features and set the usage store name. If you want to use customized configurations, you can do so before calling the start method.
Please follow the links above to see the details.
This parameter represents the optional API key, which allows apps to interact with mobile services before authentication is performed. Each MobileService can make use of the API key to interact with mobile services during the initialization process.
Generating Proxy Classes¶
You can generate proxy class Java files based on OData metadata using either the OData Gradle Plugin or the Proxy Generator CLI tool. Both tools are included in the software package.
These generated proxy classes help consume a specific OData service. Use the OData service’s metadata document to generate your data model. The generated code includes strongly typed functions to perform any OData operation on the data objects.
Proxy classes are automatically added to projects generated with the Wizard Android Studio plugin.
Using the OData Gradle Plugin¶
The OData Gradle Plugin supports OData proxy class generation with the Gradle build.
OData service metadata must be saved in a file in the project. Metadata can be downloaded from the OData service metadata URL. Check with your OData service developer or your SAP system administrator for the URL.
Adding the OData Gradle Plugin¶
To add the OData Gradle plugin to your project, edit the top-level build.gradle file of your new Android Studio project with the following:
Configuring the OData Gradle Plugin¶
To configure the plugin task for proxy class generation, add an odata closure to the module-level build.gradle file as indicated in the example in this section.
OData Plugin Configuration¶
Property | Description |
---|---|
verbose | Turn on verbose logging. Default is false. |
services | Configures the OData task to generate proxy classes for the app |
testServices | Configures the OData task to generate proxy classes for local tests |
androidTestServices | Configures the OData task to generate proxy classes for Android connected tests |
Service Proxy Class Generation Configuration¶
The following example shows some of the basic configuration elements for proxy class generation from a metadata file.
Using the OData Proxy Class Generator Command-Line Tool¶
You can also generate your proxy classes by running the OData Proxy Class Generator tool. Ensure you have a current Java installation and that it is in your system’s path.
The proxygenerator uses the following options:
Options | Description |
---|---|
-m | Metadata: metadata file |
-d | Destination: The destination where the proxy classes will be generated. (defaults to the current path) |
-h | Help |
-np | Nullable properties: All complex/entity properties are nullable. No exception is thrown when undefined. The default is false |
-p | Package: The output package name. Defaults to the CSDL Schema Namespace. |
-s | Service: The service class name. Defaults to the entity container name. |
-v | Verbose: Verbose mode on. The default is false. |
To generate proxy classes using the OData Proxy Class Generator tool:
Enter the following command in terminal to generate the Java proxy classes:
Creating the Required Credentials of Technical Users for SAP Cloud Shipment¶
You can create technical users on SAP Repositories Management site
Procedure for Creating a Technical User¶
In your browser, navigate to the SAP Repositories Management site
Enter the page of User management, initial opening of the «User management» page will automatically prompt a box for creating a technical user. You have to fill a name for it being aware that the id of your company will be added as a prefix. The name can contain only uppercase and lowercase letters as well as numbers and should be between 3 and 10 symbols long, and then click «Submit» button.
Successful creation will result in a success dialog which means that the technical user was created and distributed to the back-end systems, click «OK» button on this Success dialog.
More users can be added by clicking the button «Add» on the left of User management page bottom.
Click «Download» button in the line of Basic Auth Password to download credential, which is save to a file on your local file system: