小编wka*_*arl的帖子

ProGuard不使用okhttp

ProGuard不会与okhttp玩得很好,我会继续收到以下警告:

Warning:com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getContentLengthLong()' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl
Warning:com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getHeaderFieldLong(java.lang.String,long)' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl
Warning:com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpsURLConnection: can't find referenced method 'long getContentLengthLong()' in program class com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpURLConnection
Warning:com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpsURLConnection: can't find referenced method 'long getHeaderFieldLong(java.lang.String,long)' in program class com.squareup.okhttp.internal.huc.JavaApiConverter$CacheHttpURLConnection
Warning:there were 4 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Run Code Online (Sandbox Code Playgroud)

这些是我的okhttp和改造的proguard设置:

-dontwarn rx.**

-dontwarn okio.**

-dontwarn com.squareup.okhttp.*

-dontwarn retrofit.appengine.UrlFetchClient


-keep class …
Run Code Online (Sandbox Code Playgroud)

android proguard android-studio retrofit okhttp

22
推荐指数
3
解决办法
2万
查看次数

堆不在Genymotion模拟器上扩展

在调整大位图的大小以便更快地将图像上传到服务器时,我偶尔会遇到OutOfMemoryErrors.为了防止这种情况,我计算了所需的内存量,并在尝试缩放图像之前检查它是否超过Runtime.getRuntime().maxMemory().

但是,即使图像应该很容易放在堆上,我仍会遇到OOM错误.

仿真设备(Galaxy SII API 16)使用上述方法为我提供了67108864字节的最大内存.

在下面的代码片段中,堆大小为43975K,并且仅使用该内存的<15K.对于我的~31K分配,堆应该自动增长到大约45K,这仍然不接近64 MiB的最大大小.但正如您所看到的,dalvik vm不会扩展堆,而是耗尽内存.

10-13 20:35:57.223: D/dalvikvm(1201): GC_FOR_ALLOC freed 505K, 67% free 14692K/43975K, paused 31ms, total 31ms
10-13 20:35:57.223: I/dalvikvm-heap(1201): Forcing collection of SoftReferences for 31961100-byte allocation
10-13 20:35:57.251: D/dalvikvm(1201): GC_BEFORE_OOM freed 2K, 67% free 14689K/43975K, paused 29ms, total 29ms
10-13 20:35:57.251: E/dalvikvm-heap(1201): Out of memory on a 31961100-byte allocation.
Run Code Online (Sandbox Code Playgroud)

我想知道这是否会在真实设备上发生,或者这可能是一个genymotion错误.

堆保证扩展到maxMemory()吗?JavaDoc for Runtime.getRuntime().freeMemory()表示它"可能"扩展,无论这意味着什么.

我只需要一种可靠的方法来计算我可以使用的内存量,这就是我的方法,如果我错了请纠正我:

long maxMemory = Runtime.getRuntime().maxMemory();
long usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
long availableMemory = maxMemory - usedMemory;
Run Code Online (Sandbox Code Playgroud)

此调用导致OutOfMemoryError:

// outOptions has …
Run Code Online (Sandbox Code Playgroud)

android genymotion

6
推荐指数
1
解决办法
3498
查看次数