Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle if minifyAble set to true One Signal detects Support Library isn't added. #533

Closed
molnardindex opened this issue May 11, 2018 · 9 comments

Comments

@molnardindex
Copy link

molnardindex commented May 11, 2018

----update----
Today morning I tried to set multidexEnabled to true, than I was able to set minifyEnabled to false. Without multidexing I'm not able to set miniyEnabled to false because of 65k methods limit. With these settings One Signal works perfectly.
But if turn minifyAble to false, I get an error message, Support Library is not added to project. (Anyway which support lib is missing for OS?) But I've to add
-keep class com.google.firebase.** to prevent error reported below.

I added
-keep class com.android.support.**
-keep interface com.android.support.**
to my proguard, but it isn't solved missing support lib.
--------------
Even if I add One Signal Plugin or not, or even if I add Support Library or not, I get this error, but just if I build an APK by Build->Build APK(s) or Build->Generate Signed APK, than install and start it on device.
If I just start my app by Adnroid Studio->Run 'app', it works well, I get FCM token and my app can receive push notifications.
This is my app level build.gradle
buildscript {
ext.firebase_version = '12.0.1'
ext.support_version = '27.1.1'
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.9.0'
}
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.objectbox'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'io.fabric'
apply plugin: 'com.jakewharton.hugo'

repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://jitpack.io' }
maven { url 'https://maven.google.com' }
}

android {
signingConfigs {
release {
****
}
}
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
targetSdkVersion 27
manifestPlaceholders = [
onesignal_app_id : '******',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE']
}
testOptions {
unitTests.returnDefaultValues = true
}
flavorDimensions "default"
productFlavors {
def BOOLEAN = "boolean"
def TRUE = "true"
def FALSE = "false"
def INDEX = "index"
def CSH = "csh"
csh {
dimension "default"
versionCode 5
versionName '1.0.5'
minSdkVersion 15
applicationId "hu.cemp.csh"
buildConfigField BOOLEAN, INDEX, FALSE
buildConfigField BOOLEAN, CSH, TRUE
}
index {
dimension "default"
minSdkVersion 15
versionCode 14584
versionName '5.0.45'
applicationId "com.aff.index.main"
buildConfigField BOOLEAN, INDEX, TRUE
buildConfigField BOOLEAN, CSH, FALSE
}
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
buildTypes {
def BOOLEAN = "boolean"
def TRUE = "true"
def FALSE = "false"
def HAS_DEBUG_MENU = "HAS_DEBUG_MENU"
def REPORT_CRASHES = "REPORT_CRASHES"
canary {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationIdSuffix ".canary"
versionNameSuffix '-canary'
buildConfigField BOOLEAN, HAS_DEBUG_MENU, TRUE
debuggable true
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationIdSuffix ".debug"
versionNameSuffix '-debug'
buildConfigField BOOLEAN, HAS_DEBUG_MENU, TRUE
debuggable true
}
preview {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationIdSuffix '.preview'
versionNameSuffix '-preview'
buildConfigField BOOLEAN, HAS_DEBUG_MENU, TRUE
debuggable true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField BOOLEAN, REPORT_CRASHES, TRUE
buildConfigField BOOLEAN, HAS_DEBUG_MENU, FALSE
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
kapt {
generateStubs = true
arguments {
arg("objectbox.daoCompat", true)
}
}
}
sourceSets {
csh { assets.srcDirs = ['src/csh/assets', 'src/csh/assets/'] }
main { res.srcDirs = ['src/main/res', 'src/test/resources'] }
}
}

dependencies {
/Kotlin/
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

/*Crashlytics*/
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
    transitive = true
}

implementation files('libs/xmlwise-1_2.jar')
implementation files('libs/gemiussdk.jar')
provided 'javax.annotation:jsr250-api:1.0'

/*Android support libs*/
implementation "com.android.support:support-v4:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:appcompat-v7:26.1.1$support_version"
implementation "com.android.support:palette-v7:$support_version"
implementation "com.android.support:recyclerview-v7:$support_version"
implementation "com.android.support:cardview-v7:$support_version"
implementation "com.android.support:gridlayout-v7:$support_version"
implementation "com.android.support:preference-v7:$support_version"
implementation "com.android.support:mediarouter-v7:$support_version"
implementation "com.android.support:customtabs:$support_version"
implementation "com.android.support:support-annotations:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'

/*Firebase libs*/
implementation "com.google.firebase:firebase-core:$firebase_version"
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation "com.google.firebase:firebase-config:$firebase_version"
implementation "com.google.firebase:firebase-perf:$firebase_version"
implementation "com.google.firebase:firebase-messaging:$firebase_version"

/*Play services*/
implementation "com.google.android.gms:play-services-analytics:$firebase_version"
implementation "com.google.android.gms:play-services-location:$firebase_version"

/*One Signal*/
implementation 'com.onesignal:OneSignal:3.9.0'

/*Butterknife*/
implementation 'com.jakewharton:butterknife:8.8.1'
kapt 'com.jakewharton:butterknife-compiler:8.8.1'
/*Glide*/
implementation 'com.github.bumptech.glide:glide:4.6.1'
kapt 'com.github.bumptech.glide:compiler:4.6.1'

/*Greenrobot*/
implementation 'de.greenrobot:eventbus:2.4.0'
implementation 'org.greenrobot:greendao:3.2.2'
// all below should be added automatically by the plugin
compile "io.objectbox:objectbox-android:$objectboxVersion"
kapt "io.objectbox:objectbox-processor:$objectboxVersion"
// some useful Kotlin extension functions
compile "io.objectbox:objectbox-kotlin:$objectboxVersion"

/*Dagger*/
implementation 'com.google.dagger:dagger:2.14.1'
kapt 'com.google.dagger:dagger-compiler:2.14.1'

implementation 'com.facebook.android:facebook-android-sdk:4.16.1'
implementation 'org.jsoup:jsoup:1.9.2'
implementation 'org.jdom:jdom2:2.0.6'
implementation 'jaxen:jaxen:1.1.6'
implementation 'org.apmem.tools:layouts:1.10@aar'
implementation 'joda-time:joda-time:2.9.9'
implementation 'com.github.antonyt:InfiniteViewPager:v1.0.0'
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.1.1'
implementation 'com.squareup.okhttp:okhttp:2.0.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'org.jetbrains:annotations:15.0'
implementation 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v2.0.2'
implementation "org.greenrobot:objectbox-daocompat:$objectboxVersion"
implementation 'com.github.delight-im:Android-AdvancedWebView:v2.1.1'
provided 'javax.annotation:jsr250-api:1.0'
implementation 'javax.inject:javax.inject:1'
implementation 'com.github.deano2390:MaterialShowcaseView:1.1.0'
implementation 'com.vdurmont:emoji-java:4.0.0'
implementation 'org.apache.commons:commons-lang3:3.7'
implementation group: 'commons-io', name: 'commons-io', version: '2.5'
implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'

/*Leak canary & testing*/
canaryImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
previewImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:2.16.0'

}
apply plugin: 'com.google.gms.google-services'

@vitaliimovchan
Copy link

@molnardindex
Copy link
Author

@mvvOrigin it good to read I'm not alone with my problem. I tried to downgrade back to previous version, but is didn't solve this issue.
Anyway you said you have this issue only at release builds. Did you tried to run your debug build like I wrote above? Not with Android Studio->Run 'app', but build a debug apk by Studio->Build->Build APK(s), than install it on device (e.g. by Crashlytics).

@molnardindex
Copy link
Author

I have another project where I use One Signal. Before I was able to build a signed minified apk. Now I tried to build a debug apk without minify, and One Signal worked properly. But if I set minifyEnabled true, I get the same issue. One Signal throws an error, Android Support Library cannot been found.

@molnardindex
Copy link
Author

@mvvOrigin Today morning I found a workaround. I had to set multidexEnabled to true, than I was able to set minifyEnabled to false. Without multidex I can't turn of minify, because of 65k methods limit. If I build my apk with these settings, One Signal works.
But I'm still waiting for a solution, because I want to minify and obfuscate my app.

@molnardindex molnardindex changed the title Could not find the Android Support Library. Please make sure it has been correctly added to your project. Gradle if minifyAble set to true One Signal detects Support Library isn't added. May 14, 2018
@maxim-petlyuk
Copy link

I have the same issue with enabled proguard. I take the proguard rules from the documentation and
https://documentation.onesignal.com/docs/amazon-sdk-setup
I have also added the next line:
-dontwarn com.google.firebase.messaging.**
Note, that push messages were not sent

@yokrysty
Copy link

yokrysty commented May 16, 2018

I've encountered the same problem on release build with minify enabled.
After I investigated the source code for OneSignal I added this rules to my proguard config
This classes are used to detect support library and firebase in OSUtils.java

-keep class android.support.v4.view.MenuCompat
-keep class android.support.v4.content.WakefulBroadcastReceiver
-keep class android.support.v4.app.NotificationManagerCompat
-keep class android.support.v4.app.JobIntentService
-keep class com.google.firebase.messaging.FirebaseMessaging

@willyantows
Copy link

@yokrysty wow, thanks bro. it works

@jkasten2
Copy link
Member

@yokrysty Thanks for digging in and providing a solution.

It seems proguard started renaming public class names recently. I have updated OSUtils.java in the PR above to use the classes directly instead of Class.forName to fix this issue. This way no proguard changes will be needed as the OSUtil will be checking the existent of the renamed class.

@vitaliimovchan
Copy link

vitaliimovchan commented May 17, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants