【发布时间】:2019-10-03 11:59:50
【问题描述】:
*更新:运行 ProGuard 以减少我的资源后,ProGuard 似乎正在删除重要代码: 错误:在 org.gradle.api.Project 类型的根项目“Google 地图演示”上找不到参数 [build_7b52k4yyeks9l2efdeec28zeo$_run_closure2@6cc7c31f] 的方法 android()。 更新 build.gradle 代码:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven {
url "https://maven.google.com"
}
}
}
android {
buildTypes {
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled true
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources true
// Includes the default ProGuard rules files that are packaged with
// the Android Gradle plugin. To learn more, go to the section about
// R8 configuration files.
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我正在使用 android studio 使用 Android 的 Coding 教程 (https://www.youtube.com/watch?v=eiexkzCI8m8) 来实现 Google maps api。我在我的 Java 编译器中将此错误视为“D8 错误”和两个错误。 错误 #1:“原因:com.android.tools.r8.CompilationFailedException:编译未能完成”
错误 #2:“原因:com.android.tools.r8.utils.AbortException:错误:null,无法在单个 dex 文件中容纳请求的类(# 方法:86965 > 65536)”
有人发现问题了吗?
这是我的java代码:
public class MainActivity extends FragmentActivity implements OnMapReadyCallback{
GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
LatLng Brockton = new LatLng(42.0895988,-70.9798322);
map.addMarker(new MarkerOptions().position(Brockton).title("Brockton"));
map.moveCamera(CameraUpdateFactory.newLatLng(Brockton));
}
}
【问题讨论】:
标签: java android api google-maps