【问题标题】:Android Google Maps Services causes building errorAndroid Google Maps Services 导致构建错误
【发布时间】:2015-08-17 14:27:31
【问题描述】:

我想在我的 Android 项目中使用 Google Maps Geocoding API。所以我按照in official docs 的描述添加google-maps-services

dependencies {
    compile 'com.google.maps:google-maps-services:0.1.7'
    ...
}

并有这样的错误:

Unable to compute hash of .../release/classes.jar

我该如何解决?也许添加一些proguard规则?

感谢您的帮助!

【问题讨论】:

  • 是的,我认为你的 proguard 有一些东西,在空项目上我一切都正确。无论如何,也许 Geocoder 会帮助你developer.android.com/reference/android/location/Geocoder.html
  • 不幸的是,我必须使用谷歌地理编码库。源代码说它包含以下依赖项:compile 'com.google.code.gson:gson:2.3.1' compile 'com.squareup.okhttp:okhttp:2.0.0' compile 'joda-time:joda-time:2.4'。我已经在我的项目中使用了所有三个库。不知道怎么配置proguard?

标签: android google-maps gradle google-maps-android-api-2 proguard


【解决方案1】:

我尝试在一个空项目上实现它,并且效果很好。

我看到其他人报告说他们通过删除 minifyEnabled true 行来解决类似的问题。也许你也应该试试。

以防万一,这是我的 gradle 文件:

//Module:app

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "io.github.kylelam.geocoding"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.google.maps:google-maps-services:0.1.7'
}

//项目:地理编码

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

还有我的 onCreate 函数:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Replace the API key below with a valid API key.
    GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyCZ5QqX69Hbsx7UG2eX5rMzLLd4aiYNdJ8");
    GeocodingResult[] results = new GeocodingResult[0];
    try {
        results = GeocodingApi.geocode(context,
                "1600 Amphitheatre Parkway").await();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println(results[0].formattedAddress);

    TextView helloworld = (TextView)findViewById(R.id.helloworld);
    helloworld.setText(results[0].formattedAddress);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    • 2018-01-18
    相关资源
    最近更新 更多