Skip to content

Instantly share code, notes, and snippets.

@jkasten2
Last active June 13, 2020 01:10
Show Gist options
  • Save jkasten2/4683711807373dabaf5d5833b9574bb1 to your computer and use it in GitHub Desktop.
Save jkasten2/4683711807373dabaf5d5833b9574bb1 to your computer and use it in GitHub Desktop.
Use a local OneSignal SDK .aar file with Android Studio

Using a local onesignal.aar file

  1. Create a libs folder under the app directory in your project.
  2. Place onesignal.aar in the newly created app/libs directory.
  3. Open your project's root build.gradle file and add the folowing under repositories {...}.
flatDir {
  dirs 'libs'
}
  1. Open your app/build.gradle.
  2. Replace implementation 'com.onesignal:OneSignal:[3.14.0, 3.99.99]' with implementation(name: 'onesignal', ext: 'aar').
  3. Add required AndroidX dependencies to your app/build.gradle
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.fragment:fragment:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'

    // OR older Android Support Libraries if you haven't migrated to AndroidX yet.
    // implementation 'com.android.support:cardview-v7:[26.0.0, 27.99.99]'
    // implementation 'com.android.support:support-fragment:[26.0.0, 27.99.99]'
    // implementation 'com.android.support:customtabs:[26.0.0, 27.99.99]'
  1. Add FCM dependency if you need Google push support.
    implementation 'com.google.firebase:firebase-messaging:[10.2.1, 17.3.99]'

See the below .gradle files for full examples of the changes.

apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.onesignal.example"
manifestPlaceholders = [onesignal_app_id: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba',
onesignal_google_project_number: 'REMOTE']
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName '1.0'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// *** NEW ***
// Replaces compile 'com.onesignal:OneSignal:[3.14.0, 3.99.99]'
implementation(name: 'onesignal', ext: 'aar')
// *** NEW ***
// Add `androidx` OR `com.android.support` dependencies
// AndroidX -If you have upgrade to this already
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.fragment:fragment:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
// OR older Android Support Libraries if you haven't migrated to AndroidX yet.
// implementation 'com.android.support:cardview-v7:[26.0.0, 27.99.99]'
// implementation 'com.android.support:support-fragment:[26.0.0, 27.99.99]'
// implementation 'com.android.support:customtabs:[26.0.0, 27.99.99]'
}
// This the root build.gradle file in your project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
}
}
allprojects {
repositories {
google()
jcenter()
// *** NEW ***
// `flatDir` section
flatDir {
dirs 'libs'
}
}
}
@tanujnotes
Copy link

tanujnotes commented Jul 8, 2016

I followed these instructions but build was failing. Changing compile(name: 'OneSignal-release', ext: 'aar') to compile(name: 'onesignal-release', ext: 'aar') fixed it. It is probably because of the fact that your SDK's filename is onesignal-release.aar instead of OneSignal-release.aar. Please test and update the instructions.

@jkasten2
Copy link
Author

jkasten2 commented Jul 8, 2016

@thetanuj Thanks for the report, I updated the instructions and example file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment