在java构建路径下添加google play服务库

时间:2015-03-17 06:38:46

标签: java android eclipse google-play-services

我正在使用地图视图。我已将Google Play服务库添加到我的项目作为依赖项目,它工作正常。但是,如果我尝试将其导入到项目的libs文件夹中并将其添加到java构建路径下,则会出错。

我可以在java构建路径下添加google play服务库吗?如果不是,为什么?

错误显示在 控制台:

[2015-03-17 13:10:28 - LifeScience] '\\Dragon\d\Android\eclipse'
[2015-03-17 13:10:28 - LifeScience] CMD.EXE was started with the above path as the current directory.
[2015-03-17 13:10:28 - LifeScience] UNC paths are not supported.  Defaulting to Windows directory.
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.cast.TextTrackStyle: can't find referenced class android.view.accessibility.CaptioningManager$CaptionStyle
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.dynamic.b: can't find referenced method 'android.app.Fragment getParentFragment()' in class android.app.Fragment
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.fitness.service.FitnessSensorService$a: can't find referenced class android.app.AppOpsManager
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.fitness.service.FitnessSensorService$a: can't find referenced class android.app.AppOpsManager
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.games.internal.PopupManager$PopupManagerHCMR1: can't find referenced method 'android.view.Display getDisplay()' in class android.view.View
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.internal.an$2: can't find referenced method 'void evaluateJavascript(java.lang.String,android.webkit.ValueCallback)' in class android.webkit.WebView
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.internal.gp: can't find referenced method 'java.lang.String getDefaultUserAgent(android.content.Context)' in class android.webkit.WebSettings
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.internal.gp: can't find referenced method 'void setMediaPlaybackRequiresUserGesture(boolean)' in class android.webkit.WebSettings
[2015-03-17 13:10:28 - LifeScience] Warning: com.google.android.gms.internal.gv: can't find referenced method 'void evaluateJavascript(java.lang.String,android.webkit.ValueCallback)' in class android.webkit.WebView
[2015-03-17 13:10:28 - LifeScience]       You should check if you need to specify additional program jars.
[2015-03-17 13:10:28 - LifeScience] Warning: there were 11 unresolved references to classes or interfaces.
[2015-03-17 13:10:28 - LifeScience]          You may need to specify additional library jars (using '-libraryjars').
[2015-03-17 13:10:28 - LifeScience] Warning: there were 6 unresolved references to program class members.
[2015-03-17 13:10:28 - LifeScience]          Your input classes appear to be inconsistent.
[2015-03-17 13:10:28 - LifeScience]          You may need to recompile them and try again.
[2015-03-17 13:10:28 - LifeScience]          Alternatively, you may have to specify the option 
[2015-03-17 13:10:28 - LifeScience]          '-dontskipnonpubliclibraryclassmembers'.
[2015-03-17 13:10:28 - LifeScience] java.io.IOException: Please correct the above warnings first.
[2015-03-17 13:10:28 - LifeScience]     at proguard.Initializer.execute(Initializer.java:321)
[2015-03-17 13:10:28 - LifeScience]     at proguard.ProGuard.initialize(ProGuard.java:211)
[2015-03-17 13:10:28 - LifeScience]     at proguard.ProGuard.execute(ProGuard.java:86)
[2015-03-17 13:10:28 - LifeScience]     at proguard.ProGuard.main(ProGuard.java:492)

请帮我解决这个问题。

修改

我已将 dontwarn 添加到我的proguard.txt文件中,现在我可以导出我的应用程序了。

proguard的-project.txt

    -keepclassmembers class fqcn.of.javascript.interface.for.webview {
   public *;
}

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

-dontskipnonpubliclibraryclasses
-dontwarn com.google.**
-dontwarn android.support.v4.**

我在google上搜索过但 dontwarn 的概念对我来说并不清楚。任何人都可以解释一下 dontwarn 的作用,并且在混淆时使用它是否安全?< / p>

3 个答案:

答案 0 :(得分:2)

您必须将google-play-services-lib添加为库项目。他们更新了 SDK 。有几个教程。对于 Eclipse ,这很简单:

Right click project -> properties -> Android

enter image description here

答案 1 :(得分:0)

Google Play服务的Proguard配置

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

来源:Android Developer

答案 2 :(得分:0)

您必须将Google Play服务导入为项目。然后转到您的项目属性,然后转到Android构建路径(您选择sdk版本),然后单击添加到Google Play服务项目。清理并构建它。