我正在尝试在我的应用中使用 Dagger 2。我不断收到此错误:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. java.lang.IllegalArgumentException: @dagger.Module does not define an element subcomponents()
我根本不在应用程序中使用子组件,所以我不知道为什么会出现此错误。我有一个模块和一个组件。模块:
@Singleton
@Module
public class ApplicationModule {
private final WSTApplication application;
public ApplicationModule(WSTApplication application) {
this.application = application;
}
@Provides
public WSTApplication application() {
return this.application;
}
@Provides
public Context applicationContext() {
return this.application;
}
@Provides
Realm provideRealm() {
return Realm.getDefaultInstance();
}
@Provides
RealmHelper providesRealmHelper(final Realm realm) {
return new RealmHelper(realm);
}
@Provides
@Singleton
public WorkoutPresenter providesWorkoutPresenter(final RealmHelper helper) {
return new WorkoutPresenter(helper);
}
还有我的组件:
@Singleton
@Component(modules={ApplicationModule.class})
public interface ApplicationComponent {
void inject (MainActivity activity);
WSTApplication application();
Context applicationContext();
Realm provideRealm();
RealmHelper providesRealmHelper(Realm realm);
WorkoutPresenter providesWorkoutPresenter(RealmHelper helper);
}
这是我的应用程序的 onCreate:
@Override
public void onCreate() {
super.onCreate();
component = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this))
.build();
}
我也无法让 DaggerApplicationComponent 停止显示为红色,但我认为这是因为这个奇怪的子组件错误导致项目实际上并未构建?我试过使用下划线 (Dagger_ApplicationComponent),但这没有用。
我试过谷歌,但我发现的只是关于如何在 Dagger 中使用子组件的指南,这不是我想要的。我不想使用子组件。我只想使用一个组件。
此外,为了以防万一,这是我放入 build.gradle 文件中的内容:
在项目构建脚本中:
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
并且在应用级别的 build.gradle 中:
apply plugin: 'com.neenbedankt.android-apt'
然后在依赖项中向下:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.dagger:dagger:2.1'
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
apt 'com.google.dagger:dagger-compiler:2.7'
provided 'org.glassfish:javax.annotation:10.0-b28'
}
感谢任何能帮助我的人!我是 Dagger2 的新手,甚至在阅读了几本初学者指南之后,我仍然没有完全理解它(我希望尝试使用它会让事情变得更清楚......到目前为止它就像漏油一样清晰)。很可能我犯了一个愚蠢的初学者错误,提前道歉。
最佳答案
为什么使用 com.neenbedankt.android-apt?据我所知it is obsolete now .
Dagger GitHub page解释了如何在 Android 项目中使用它。
dependencies {
compile 'com.google.dagger:dagger:2.x'
annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
}
在这里你可以找到Dagger releases对于依赖项版本。
我不确定它是否能立即解决您的问题,但您一定要试一试。
关于android - Dagger 2 : Error about subcomponents, 但我的应用程序中没有任何子组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42053787/
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我正在处理旧代码的一部分。beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)endRubocop错误如下:Avoidstubbingusing'allow_any_instance_of'我读到了RuboCop::RSpec:AnyInstance我试着像下面那样改变它。由此beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)end对此:let(:sport_
我喜欢使用Textile或Markdown为我的项目编写自述文件,但是当我生成RDoc时,自述文件被解释为RDoc并且看起来非常糟糕。有没有办法让RDoc通过RedCloth或BlueCloth而不是它自己的格式化程序运行文件?它可以配置为自动检测文件后缀的格式吗?(例如README.textile通过RedCloth运行,但README.mdown通过BlueCloth运行) 最佳答案 使用YARD直接代替RDoc将允许您包含Textile或Markdown文件,只要它们的文件后缀是合理的。我经常使用类似于以下Rake任务的东西:
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我