{"_id":"5c73e163ad58c70033b96fbc","project":"54aa7f773b56130b0056c86e","version":{"_id":"55781fe25129590d003ff4f7","project":"54aa7f773b56130b0056c86e","forked_from":"54aa7f773b56130b0056c871","__v":8,"createdAt":"2015-06-10T11:30:42.700Z","releaseDate":"2015-06-10T11:30:42.700Z","categories":["55781fe35129590d003ff4f8","55781fe35129590d003ff4f9","55781fe35129590d003ff4fa","55781fe35129590d003ff4fb","55781fe35129590d003ff4fc","55781fe35129590d003ff4fd","55781fe35129590d003ff4fe","564bbc7e8841060d00abb2ee","565b66c446118c0d00dcb0bb","56898269f8dc340d00308c13","582318b23b961a0f009516a1","594a848c9f4771001a43c959","5c73dd27e8fdc000572a206a","5c77ac5af94a920045cb80ca"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Developers","version_clean":"2.0.0","version":"2.0"},"category":{"_id":"5c77ac5af94a920045cb80ca","project":"54aa7f773b56130b0056c86e","version":"55781fe25129590d003ff4f7","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2019-02-28T09:39:38.102Z","from_sync":false,"order":5,"slug":"react","title":"React Native SDK"},"user":"57bc3654b9c7f0220009c77b","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2019-02-25T12:36:51.867Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"Before reading this guide make sure that you have properly setup your React App using our guide under - https://pulsate.readme.io/v2.0/docs/installing-the-react-plugin\n\nThis guide will take you through all the steps that are needed to properly setup your Android App and run the Pulsate SDK. Using Android Studio open the \"android\" project that was created from the previous guide.\n[block:api-header]\n{\n  \"title\": \"1. Setting App to use Android 27\"\n}\n[/block]\nThe Pulsate SDK currently supports Android 27, but our React App has been created to support Android 28 and this causes many compile errors to show up. To remove these errors we must make our React App support also Android 27.\n\nFirst we need to open our android/build.gradle file and change the *buildToolsVersion, minSdkVersion, compileSdkVersion, targetSdkVersion, supportLibVersion*.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"buildscript {\\n    ext {\\n        buildToolsVersion = \\\"27.0.3\\\"\\n        minSdkVersion = 16\\n        compileSdkVersion = 27\\n        targetSdkVersion = 27\\n        supportLibVersion = \\\"27.1.1\\\"\\n    }\\n}\\n\\n\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThe newest version of gradle also only supports Android 28, so we must also move to an older version. In the same file update your *gradle dependencies* and the *gradle task wrapper*.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \" dependencies {\\n    classpath 'com.android.tools.build:gradle:3.1.4'\\n}\\n\\ntask wrapper(type: Wrapper) {\\n    gradleVersion = '4.4'\\n    distributionUrl = distributionUrl.replace(\\\"bin\\\", \\\"all\\\")\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThere is one more place that we must update to properly revert gradle to an older version. Open the *gradle-wrapper.properties* and update it to the following\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"distributionBase=GRADLE_USER_HOME\\ndistributionPath=wrapper/dists\\nzipStoreBase=GRADLE_USER_HOME\\nzipStorePath=wrapper/dists\\ndistributionUrl=https\\\\://services.gradle.org/distributions/gradle-4.4-all.zip\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nWith this we should have properly setup our Android App to work with Android 27.\n[block:api-header]\n{\n  \"title\": \"2. Configure Gradle\"\n}\n[/block]\nIn this step we will add all dependencies that are needed by the Pulsate SDK.\n\nWe will be adding changes to the *android/app/build.gradle*. Find the *android/app/build.gradle* file and open it. As the Android platform has continued to grow, so has the size of Android apps. When your application and the libraries it references reach a certain size, you encounter build errors that indicate your app has reached a limit of the Android app build architecture. To fix this we must enable multiDex for the App.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"android {\\n    defaultConfig {\\n    \\t\\t...\\n        multiDexEnabled = true\\n    }\\n}\\n\\ndependencies {\\n    implementation 'com.android.support:multidex:1.0.3'\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThe Pulsate SDK uses dataBinding and Java8 features so we must also add them.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"android {\\n\\t\\tdataBinding {\\n        enabled true\\n    }\\n    compileOptions {\\n        sourceCompatibility JavaVersion.VERSION_1_8\\n        targetCompatibility JavaVersion.VERSION_1_8\\n    }\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThe React Plugin uses NDK and requires a few changes to run properly after we reverted to an older React version. First we must add *ndk abiFilters* in our *defaultConfig* \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"android {\\n    defaultConfig {\\n    \\t\\t...\\n        ndk {\\n            abiFilters \\\"armeabi-v7a\\\", \\\"x86\\\"\\n        }\\n    }\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nNext we need to update our *abi split* \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"android {\\n    splits {\\n        abi {\\n            reset()\\n            enable enableSeparateBuildPerCPUArchitecture\\n            universalApk false  // If true, also generate a universal APK\\n            include \\\"armeabi-v7a\\\", \\\"x86\\\"\\n        }\\n    }\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThe last change is for our *applicationVariants* \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"android {\\n    applicationVariants.all { variant ->\\n        variant.outputs.each { output ->\\n            // For each separate APK per architecture, set a unique version code as described here:\\n            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits\\n            def versionCodes = [\\\"armeabi-v7a\\\":1, \\\"x86\\\":2]\\n            def abi = output.getFilter(OutputFile.ABI)\\n            if (abi != null) {  // null for the universal-debug, universal-release variants\\n                output.versionCodeOverride =\\n                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode\\n            }\\n        }\\n    }\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"3. Running Pulsate and MultiDex\"\n}\n[/block]\nWith our dependencies added we can now run Pulsate and MultiDex.\n\nSearch for the* MainApplication.jave* file and open it. To properly run MultiDex add the following code\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::Override\\nprotected void attachBaseContext(Context base) {\\n    super.attachBaseContext(base);\\n    MultiDex.install(base);\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nTo run Pulsate add the following code \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\npublic void onCreate() {\\n    super.onCreate();\\n    Pulsate.install(this);\\n    AuthorizationData authData = new AuthorizationData(\\\"APP_ID\\\", \\\"APP_KEY\\\", \\\"GCM_APP_ID\\\");\\n    PulsateFactory.getInstance().setAuthorizationData(authData);\\n    SoLoader.init(this, /* native exopackage */ false);\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n*APP_ID* and *APP_KEY* are used to associate the Pulsate SDK with your Pulsate Web Application which you have created using our Pulsate Web Console. *APP_ID* and *APP_KEY* can be found in your application configuration panel. To find them open admin panel, and then go to *Settings -> App Settings* screen in the Pulsate web console. \n\n*GCM_APP_ID* is used to send push notifications, later in this tutorial you will find out how to create your Google Cloud Messaging account.\n[block:api-header]\n{\n  \"title\": \"4. Building and Running the App\"\n}\n[/block]\nWith everything setup we can now try to build and run the App on a device.\n\nIf you are getting build errors please delete files in app/build, clean build,, Invalidate Caches and Restart, delete files in .gradle, delete npm_modules folder from the main React Folder and run “npm install” to reinstall all React dependencies.\n\nIf you get and error caused by bad characters in settings.gradle update the projectDir to the following\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"project(':pulsate-react-native-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/pulsate-react-native-sdk/android')\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"setting-up-the-pulsate-react-sdk-android","type":"basic","title":"Setting up the Pulsate React SDK - Android"}

Setting up the Pulsate React SDK - Android


Before reading this guide make sure that you have properly setup your React App using our guide under - https://pulsate.readme.io/v2.0/docs/installing-the-react-plugin This guide will take you through all the steps that are needed to properly setup your Android App and run the Pulsate SDK. Using Android Studio open the "android" project that was created from the previous guide. [block:api-header] { "title": "1. Setting App to use Android 27" } [/block] The Pulsate SDK currently supports Android 27, but our React App has been created to support Android 28 and this causes many compile errors to show up. To remove these errors we must make our React App support also Android 27. First we need to open our android/build.gradle file and change the *buildToolsVersion, minSdkVersion, compileSdkVersion, targetSdkVersion, supportLibVersion*. [block:code] { "codes": [ { "code": "buildscript {\n ext {\n buildToolsVersion = \"27.0.3\"\n minSdkVersion = 16\n compileSdkVersion = 27\n targetSdkVersion = 27\n supportLibVersion = \"27.1.1\"\n }\n}\n\n", "language": "text" } ] } [/block] The newest version of gradle also only supports Android 28, so we must also move to an older version. In the same file update your *gradle dependencies* and the *gradle task wrapper*. [block:code] { "codes": [ { "code": " dependencies {\n classpath 'com.android.tools.build:gradle:3.1.4'\n}\n\ntask wrapper(type: Wrapper) {\n gradleVersion = '4.4'\n distributionUrl = distributionUrl.replace(\"bin\", \"all\")\n}", "language": "text" } ] } [/block] There is one more place that we must update to properly revert gradle to an older version. Open the *gradle-wrapper.properties* and update it to the following [block:code] { "codes": [ { "code": "distributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-4.4-all.zip", "language": "text" } ] } [/block] With this we should have properly setup our Android App to work with Android 27. [block:api-header] { "title": "2. Configure Gradle" } [/block] In this step we will add all dependencies that are needed by the Pulsate SDK. We will be adding changes to the *android/app/build.gradle*. Find the *android/app/build.gradle* file and open it. As the Android platform has continued to grow, so has the size of Android apps. When your application and the libraries it references reach a certain size, you encounter build errors that indicate your app has reached a limit of the Android app build architecture. To fix this we must enable multiDex for the App. [block:code] { "codes": [ { "code": "android {\n defaultConfig {\n \t\t...\n multiDexEnabled = true\n }\n}\n\ndependencies {\n implementation 'com.android.support:multidex:1.0.3'\n}", "language": "text" } ] } [/block] The Pulsate SDK uses dataBinding and Java8 features so we must also add them. [block:code] { "codes": [ { "code": "android {\n\t\tdataBinding {\n enabled true\n }\n compileOptions {\n sourceCompatibility JavaVersion.VERSION_1_8\n targetCompatibility JavaVersion.VERSION_1_8\n }\n}", "language": "text" } ] } [/block] The React Plugin uses NDK and requires a few changes to run properly after we reverted to an older React version. First we must add *ndk abiFilters* in our *defaultConfig* [block:code] { "codes": [ { "code": "android {\n defaultConfig {\n \t\t...\n ndk {\n abiFilters \"armeabi-v7a\", \"x86\"\n }\n }\n}", "language": "text" } ] } [/block] Next we need to update our *abi split* [block:code] { "codes": [ { "code": "android {\n splits {\n abi {\n reset()\n enable enableSeparateBuildPerCPUArchitecture\n universalApk false // If true, also generate a universal APK\n include \"armeabi-v7a\", \"x86\"\n }\n }\n}", "language": "text" } ] } [/block] The last change is for our *applicationVariants* [block:code] { "codes": [ { "code": "android {\n applicationVariants.all { variant ->\n variant.outputs.each { output ->\n // For each separate APK per architecture, set a unique version code as described here:\n // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits\n def versionCodes = [\"armeabi-v7a\":1, \"x86\":2]\n def abi = output.getFilter(OutputFile.ABI)\n if (abi != null) { // null for the universal-debug, universal-release variants\n output.versionCodeOverride =\n versionCodes.get(abi) * 1048576 + defaultConfig.versionCode\n }\n }\n }\n}", "language": "text" } ] } [/block] [block:api-header] { "title": "3. Running Pulsate and MultiDex" } [/block] With our dependencies added we can now run Pulsate and MultiDex. Search for the* MainApplication.jave* file and open it. To properly run MultiDex add the following code [block:code] { "codes": [ { "code": "@Override\nprotected void attachBaseContext(Context base) {\n super.attachBaseContext(base);\n MultiDex.install(base);\n}", "language": "java" } ] } [/block] To run Pulsate add the following code [block:code] { "codes": [ { "code": "@Override\npublic void onCreate() {\n super.onCreate();\n Pulsate.install(this);\n AuthorizationData authData = new AuthorizationData(\"APP_ID\", \"APP_KEY\", \"GCM_APP_ID\");\n PulsateFactory.getInstance().setAuthorizationData(authData);\n SoLoader.init(this, /* native exopackage */ false);\n}", "language": "java" } ] } [/block] *APP_ID* and *APP_KEY* are used to associate the Pulsate SDK with your Pulsate Web Application which you have created using our Pulsate Web Console. *APP_ID* and *APP_KEY* can be found in your application configuration panel. To find them open admin panel, and then go to *Settings -> App Settings* screen in the Pulsate web console. *GCM_APP_ID* is used to send push notifications, later in this tutorial you will find out how to create your Google Cloud Messaging account. [block:api-header] { "title": "4. Building and Running the App" } [/block] With everything setup we can now try to build and run the App on a device. If you are getting build errors please delete files in app/build, clean build,, Invalidate Caches and Restart, delete files in .gradle, delete npm_modules folder from the main React Folder and run “npm install” to reinstall all React dependencies. If you get and error caused by bad characters in settings.gradle update the projectDir to the following [block:code] { "codes": [ { "code": "project(':pulsate-react-native-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/pulsate-react-native-sdk/android')", "language": "text" } ] } [/block]