我想在Android项目中使用Google Maps Geocoding API。所以我按行{<3}}添加google-maps-services
行:
dependencies {
compile 'com.google.maps:google-maps-services:0.1.7'
...
}
并且有这样的错误:
Unable to compute hash of .../release/classes.jar
我该如何解决?也许添加一些proguard规则?
谢谢你的帮助!
答案 0 :(得分:2)
我试图在一个空项目上实现它,它工作正常。
我看到其他人报告他们通过删除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);