gpt4 book ai didi

java - 使用Gradle编译Android项目时出现"Error: cannot find symbol"

转载 作者:太空宇宙 更新时间:2023-11-04 14:44:28 24 4
gpt4 key购买 nike

由于以下错误,我无法使用 Gradle 编译我的 Android 项目:

:compileDebugJava
(...)/src/org/drzewo/openmrs/android/andromeda/dialog/DateTimeFragment.java:101: error: cannot find symbol
public interface Callbacks extends ActivityCallbacks {
^
symbol: class ActivityCallbacks
location: class DateTimeFragment
(...)/src/org/drzewo/openmrs/android/andromeda/dialog/DateTimeFragment.java:53: error: method asCallbacks in class Util cannot be applied to given types;
mPickerOptions = Util.asCallbacks(activity, Callbacks.class).getPickerOptions();
^
required: Activity,Class<T>
found: Activity,Class<Callbacks>
reason: inferred type does not conform to declared bound(s)
inferred: Callbacks
bound(s): ActivityCallbacks
where T is a type-variable:
T extends ActivityCallbacks declared in method <T>asCallbacks(Activity,Class<T>)
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
:compileDebugJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJava'.
> Compilation failed; see the compiler error output for details.

有问题的源文件是:

package org.drzewo.openmrs.android.andromeda.dialog;

import java.util.Calendar;

import org.drzewo.openmrs.android.andromeda.R;
import org.drzewo.openmrs.android.andromeda.dialog.DateTimePickerActivity.PickerOptions;
import org.drzewo.openmrs.android.andromeda.event.OnDateTimeSelected;
import org.drzewo.openmrs.android.andromeda.util.ActivityCallbacks;
import org.drzewo.openmrs.android.andromeda.util.Util;

import roboguice.event.EventManager;
import roboguice.fragment.RoboFragment;
import roboguice.inject.InjectView;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;

import com.google.inject.Inject;

public class DateTimeFragment extends RoboFragment implements OnClickListener {

@Inject
private EventManager mEventManager;

@InjectView(R.id.date)
private DatePicker mDate;

@InjectView(R.id.time)
private TimePicker mTime;

@InjectView(R.id.ok_button)
private Button mOkButton;

private PickerOptions mPickerOptions;

public DateTimeFragment() {
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mPickerOptions = Util.asCallbacks(activity, Callbacks.class).getPickerOptions();
if (mPickerOptions == null) {
throw new IllegalArgumentException("No picker options provided");
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_date_time, container, false);
}

@SuppressWarnings("incomplete-switch")
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
switch (mPickerOptions) {
case DATE:
mTime.setVisibility(View.GONE);
break;
case TIME:
mDate.setVisibility(View.GONE);
mTime.setIs24HourView(true);
break;
}
mOkButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if (mOkButton == v) {
final Calendar calendar = Calendar.getInstance();
switch (mPickerOptions) {
case DATE:
calendar.set(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth());
break;
case TIME:
calendar.set(0, 0, 0, mTime.getCurrentHour(), mTime.getCurrentMinute());
break;
case DATE_TIME:
calendar.set(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth(),
mTime.getCurrentHour(), mTime.getCurrentMinute());
break;
}
mEventManager.fire(new OnDateTimeSelected(calendar.getTime()));
}
}

public interface Callbacks extends ActivityCallbacks {
PickerOptions getPickerOptions();
}
}

看起来像

import org.drzewo.openmrs.android.andromeda.util.ActivityCallbacks;

线路无法正常工作,但如果我更改

public interface Callbacks extends ActivityCallbacks {

行至

public interface Callbacks extends org.drzewo.openmrs.android.andromeda.util.ActivityCallbacks {

然后一切正常。

所以我知道解决方法,但只是不想在不了解问题根源的情况下应用它。导入行是有效的,在其他几个文件中完全相同的解决方案不会导致任何错误。当我使用 Eclipse 而不是 Gradle 来构建项目时,一切正常。

这是我的 build.gradle 脚本:

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'org.xtend:xtend-gradle-plugin:0.1.+'
classpath 'com.android.tools.build:gradle:0.12.+'
}
}

apply plugin: 'xtend-android'
apply plugin: 'android'
apply plugin: 'eclipse'

group = projectGroup
version = projectVersion

sourceCompatibility = 1.6
targetCompatibility = 1.6

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.6.2'
compile 'com.android.support:support-v4:20.0.0'
compile 'org.drzewo.openmrs:jomrsa:0.8.0'
compile 'org.roboguice:roboguice:2.0'
compile 'commons-codec:commons-codec:1.8'
compile 'org.apache.httpcomponents:httpclient-android:4.3.3'
}

android {
compileSdkVersion 15
buildToolsVersion '20.0.0'

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
resources {
exclude '**/*.xtend'
}
}

instrumentTest.setRoot('tests')

debug.setRoot('build-types' + File.separator + 'debug')
release.setRoot('build-types' + File.separator + 'release')
}

packagingOptions {
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/NOTICE'
}

lintOptions {
abortOnError false
}
}

eclipse {
project {
name = rootProject.name

buildCommands = [
'org.eclipse.xtext.ui.shared.xtextBuilder',
'com.android.ide.eclipse.adt.ResourceManagerBuilder',
'com.android.ide.eclipse.adt.PreCompilerBuilder',
'org.eclipse.jdt.core.javabuilder',
'com.android.ide.eclipse.adt.ApkBuilder'
]

natures = [
'org.springsource.ide.eclipse.gradle.core.nature',
'org.eclipse.xtext.ui.shared.xtextNature',
'com.android.ide.eclipse.adt.AndroidNature',
'org.eclipse.jdt.core.javanature'
]
}
}

task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}

apply from: 'gradle' + File.separator + 'copyLibs.gradle'

所以问题是:为什么我会遇到这个问题以及我应该如何解决它?

PS。如果有人想编译上述项目:它托管在 Fossil 存储库 here 中,其依赖的项目为 here (也在化石库中)。服务器使用自签名证书,因此浏览器可能会提示。

最佳答案

我记得,这是因为其中一个模块缺少 build.gradle

关于java - 使用Gradle编译Android项目时出现"Error: cannot find symbol",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24597730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com