由于以下错误,我无法使用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(在Fossil存储库中也是如此)。服务器使用自签名证书,因此浏览器可能会抱怨它。
答案 0 :(得分:0)
我记得,其中一个模块缺少build.gradle
。