Android Google map 服务导致构建错误

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

我想在我的 Android 项目中使用 Google map 地理编码 API。因此,我按照描述添加 google-maps-services in official docs按行:

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

并出现这样的错误:

无法计算 .../release/classes.jar 的哈希

我该如何解决这个问题?也许添加一些混淆器规则?

感谢您的帮助!

最佳答案

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

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

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

//模块:应用

    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);

关于Android Google map 服务导致构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32052968/

相关文章:

java - 如何设置CameraX(Android)5秒后停止录制?

html - 如何使用谷歌地图显示您网站上的 map 位置

google-maps - 谷歌地图地点标签语言

gradle - 如何使用SerenityRunner和Gradle运行带有 'WithTagValuesOf'注释的特定测试

android - 如何在 Android 中解析从 facebook 接收到的包数据?

android - 如何使用传感器获取手机的角度/度数?

android - Google map V2 - 授权失败,我无法显示 map

android - 文件 'root/lib/META-INF/MANIFEST.MF' 使用保留文件或目录名称 'lib'

android - 使用 gradle 从存储库下载 apk

android - 我的自定义 ListView 元素的位置顺序有问题