0

When I tried to Generate Signed Apk in android studio 1.5.1 and completing the Dialog appeared about this process, I faced with this message and building aborted:

    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Call
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.ResponseBody
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.ResponseBody
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Call
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.ResponseBody
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.OkHttpClient
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.CacheControl
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Request$Builder
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Response
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.ResponseBody
    Warning:com.squareup.picasso.OkHttpDownloader: can't find referenced class com.squareup.okhttp.Cache

build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        ....
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            consumerProguardFiles 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.jakewharton:butterknife:8.0.1'
    android{
        useLibrary  'org.apache.http.legacy'
    }
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.onesignal:OneSignal:2.+@aar'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.google.android.gms:play-services-analytics:+'
    compile 'com.google.android.gms:play-services-location:+'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'com.github.lzyzsd:circleprogress:1.1.0@aar'
}

proguard-rules.txt :

    # This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags.  Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik.  The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.)  Make sure you
# test thoroughly if you go this route.
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify

# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

-keep com.squareup.picasso.** { ; }
-dontwarn com.squareup.picasso.*

After a lot of searching, I understood that I should use -dontwarn com.squareup.picasso.* but nothing happened! and I still have the same problem.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ali Soleimani
  • 301
  • 1
  • 4
  • 16

3 Answers3

3

There are couple of bugs in your build.gradle. Let's fix them, it should solve the problems for you.

  1. ProGuard config file definition in the Gradle script

This is probably the root cause of your problems. Are you really sure your ProGuard config file proguard-rules.txt is used? Because it doesn't seem so from the build script. You use

android {
    …
    buildTypes {
        release {
            minifyEnabled true
            consumerProguardFiles 'proguard-rules.txt'
        }
    }
}

but that config is not valid for an application, consumerProguardFiles is designed for android library projects only. It tells the library project to package the specified ProGuard config files into the output aar.

In application you have to use

android {
    ...
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard-rules.txt', getDefaultProguardFile('proguard-android.txt')
        }
    }
}

The config proguardFiles tells the build to apply the specified ProGuard config files. So that means it's not defined for your build.

Note that the default ProGuard file contains general Android rules that are necessary for all Android apps (and some rules are added by the Android Gradle plugin). It seems you copied most of the default rules into your config. Best practice is to use the default ProGuard config file, don't copy them into your own config.

  1. Adjust ProGuard config rules

You don't need this rule

-keep com.squareup.picasso.** { ; }

Add rules for ignoring those Picasso warnings. You can use either

-dontwarn com.squareup.okhttp.**

or

-dontwarn com.squareup.picasso.OkHttpDownloader
  1. Place useLibrary statement at the correct place.

This is a minor thing, but you should shill fix it. Don't place useLibrary into dependencies closure. It belong into android closure.

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'
    …
}

Btw: it's really advised to get rid of HttpClient. Ideally use OkHttp.

Tomik
  • 23,857
  • 8
  • 121
  • 100
0

Do Like this in build.gradle:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"
    useLibrary 'org.apache.http.legacy'
    ...
}
viana
  • 495
  • 4
  • 18
  • 42
  • i put your code in build.gradle but this error apeared `Error:Timeout waiting to lock cp_proj class cache for build file 'C:\Users\A.S.R\AndroidStudioProjects\Teroject\app\build.gradle' (C:\Users\A.S.R\.gradle\caches\2.8\scripts\build_4rnkp3frs7d5k4pjqcgs8zqjt\cp_proj). It is currently in use by another Gradle instance. Owner PID: unknown Our PID: 4812 Owner Operation: unknown Our operation: Initialize cache Lock file: C:\Users\A.S.R\.gradle\caches\2.8\scripts\build_4rnkp3frs7d5k4pjqcgs8zqjt\cp_proj\cache.properties.lock` – Ali Soleimani Aug 16 '16 at 20:51
  • Well the positioning of `useLibrary` statement was wrong, but this doesn't solve the problem. – Tomik Aug 17 '16 at 10:41
0

Here is an answer and Proguard configuration for Picasso from Jake Wharton:

### PICASSO

# Checks for OkHttp versions on the classpath to determine Downloader to use.
-dontnote com.squareup.picasso.Utils
# Downloader used only when OkHttp 2.x is present on the classpath.
-dontwarn com.squareup.picasso.OkHttpDownloader
# Downloader used only when OkHttp 3.x is present on the classpath.
-dontwarn com.squareup.picasso.OkHttp3Downloader


### OKHTTP

# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote okhttp3.internal.Platform


### OKIO

# java.nio.file.* usage which cannot be used at runtime. Animal sniffer annotation.
-dontwarn okio.Okio
# JDK 7-only method which is @hide on Android. Animal sniffer annotation.
-dontwarn okio.DeflaterSink

Github issue in Picasso

Gaket
  • 6,533
  • 2
  • 37
  • 67