1

我尝试将 sbt 和 maven 用于 android-scala,我非常喜欢 maven 来完成整个发布工作(ProGuard-ing scala 标准库等)。但我想要在我的 IDE - IntelliJ IDEA 中进行轻量级的重新编译循环进行开发。

问题是 scala 文件无法编译。我这样配置我的项目:

  • 创建安卓项目
  • 添加了scala方面
  • 将 Scala 编译器设置为全局
  • 添加了对 scala 库(全局)的依赖并将其设置为“提供”

我添加了一个 scala 对象并从 java Activity 中引用它。ClassNotFoundException 并强制关闭。它编译干净(而且非常快)。

我以相同的方式创建了一个普通的旧 java 项目,并使用相同的全局库,它工作正常。对 apk 的检查显示它包含 scala 源(!)文件。所以显然它没有尝试编译。

哦,我的手机已经预装了来自 Play 商店的 scala 安装程序。

我使用 IntelliJ IDEA 11 社区。几个月前我第一次尝试这个,它奏效了。

更新它可以在不同的机器上运行。

4

2 回答 2

0

您可能不得不摆弄您的“proguard.cfg”文件。

这是我在使用 Scala 2.10 和 Android 以及 IntelliJ IDE 的项目中使用的一个(更改第一个选项以匹配您的包名称):

##
## Keep classes of named package
##
-keep public class **.keithpinson.**
## ## ## ## ## ## ## ## ## ## ## ## ##


##
## RELEASE ONLY
##
##-optimizationpasses 3
##-overloadaggressively
##-repackageclasses ''
##-allowaccessmodification
##-optimizations !code/simplification/arithmetic
##         ,!field/*,!class/merging/*,!code/allocation/variable
##-keepattributes *Annotation*

##
## DEBUG ONLY
##
-dontobfuscate
-dontoptimize
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
## -printmapping mapping.txt


##
## ALL VERSIONS
##
-dontpreverify
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontusemixedcaseclassnames


## Keep Limited Serializable Capability
##-keepclassmembers class * implements java.io.Serializable {
##    static long serialVersionUID;
##    private void writeObject(java.io.ObjectOutputStream);
##    private void readObject(java.io.ObjectInputStream);
##    java.lang.Object writeReplace();
##    java.lang.Object readResolve();
##}

## Keep All Serializable Capability
##-keep class * implements java.io.Serializable { *; }"





##
## ANDROID SETTINGS
##
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-dontwarn com.google.common.primitives.UnsignedBytes$*

-dontnote android.app.backup.BackupAgentHelper
-dontnote com.android.vending.licensing.ILicensingService

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

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

# R classes may be built out of sequence so don't proguard them
-keep public class **.R { *; }
-keepclassmembers class **.R$* {
    public static <fields>;
}

# Removes all calls to Log. Delete the methods you want to keep.
-assumenosideeffects class android.util.Log {
    public static int v(...);
    #public static int d(...);
    public static int i(...);
    #public static int w(...);
    #public static int e(...);
    #public static int wtf(...);
}

## Fixes ==> Warning: ... can't find referenced class javax.xml.stream.events.XMLEvent
## -dontwarn javax.xml.**


## If using Guice
## -keep class com.google.common.base.Finalizable* {
##   <fields>;
##   <methods>;
## }
##
## -keep class com.google.common.base.internal.Finalizer {
##   <fields>;
##   <methods>;
## }


##
## SCALA SETTINGS
##
-dontwarn **$$anonfun$*
-dontwarn scala.android.**
-dontwarn scala.beans.ScalaBeanInfo
-dontwarn scala.collection.generic.GenTraversableFactory
-dontwarn scala.collection.immutable.RedBlack$Empty
-dontwarn scala.concurrent.forkjoin.**
-dontwarn scala.reflect.**
-dontwarn scala.sys.process.**
-dontwarn scala.tools.**,plugintemplate.**


#(org.xml.sax.EntityResolver)Class.forName(variable).newInstance()
-dontnote org.xml.sax.EntityResolver

#(org.apache.james.mime4j.storage.StorageProvider)Class.forName(variable).newInstance()
-dontnote org.apache.james.mime4j.storage.DefaultStorageProvider

-dontnote scala.android.app.Activity


## Keep All Scala Classes
##-keep class scala.** { *; }

-keep class scala.android.package**
-keep class * extends scala.android.app.Activity

## Fixes ==> Warning: ... can't find referenced class sun.misc.Unsafe
-libraryjars libs/jsr305-2.0.1.jar
-dontwarn sun.misc.Unsafe


-keep class * extends scala.runtime.MethodCache {
    public <methods>;
}

-keepclassmembers class * {
    ** MODULE$;
}

-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinPool {
    long eventCount;
    int workerCounts;
    int runControl;
    scala.concurrent.forkjoin.ForkJoinPool$WaitQueueNode syncStack;
    scala.concurrent.forkjoin.ForkJoinPool$WaitQueueNode spareStack;
}

-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinWorkerThread {
    int base;
    int sp;
    int runState;
}

-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinTask {
    int status;
}

-keepclassmembernames class scala.concurrent.forkjoin.LinkedTransferQueue {
    scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference head;
    scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference tail;
    scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference cleanMe;
}
于 2012-09-08T14:34:01.803 回答
0

似乎想法会在取消选中 Run ProGuard on Android facet 时使用系统 proguard 配置来优化 jar,简单取消选中它似乎不起作用,所以你需要为 proguard 使用一些自定义配置,试试这个,它对我有用,拜托用你的包裹替换 REPLACE WITH YOUR PACKAGE

当然,你可以试试 Keith 的配置。

-dontobfuscate
-dontoptimize
-dontpreverify

-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers

-dontwarn

#scala.Enumeration accesses a field 'MODULE$' dynamically
-dontnote scala.Enumeration

#(org.xml.sax.EntityResolver)Class.forName(variable).newInstance()
-dontnote org.xml.sax.EntityResolver

#(org.apache.james.mime4j.storage.StorageProvider)Class.forName(variable).newInstance()
-dontnote org.apache.james.mime4j.storage.DefaultStorageProvider

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
            SourceFile,LineNumberTable,Annotation,EnclosingMethod

-keep public class REPLACE WITH YOUR PACKAGE

https://plus.google.com/106066742926663025812/posts/41XoDPeDEqc

于 2012-12-18T02:14:32.197 回答