我从https://github.com/robolectric/deckard-gradle下载了Robolectric deckard-gradle项目并导入到Android Studio.
在我第一次跑步时,我得到了
!!! JUnit version 3.8 or later expected:
java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
Run Code Online (Sandbox Code Playgroud)
错误,我从.iml修复此问题.
然后我得到了:
Class Not Found "my test class"
Run Code Online (Sandbox Code Playgroud)
我尝试了几十种解决方案,我在谷歌中发现了这个问题,但没有一个有效.
我在我的活动onCreate()中初始化我的列表,如下所示:
private List<MyItem> filtered;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
filtered = new ArrayList<>();
// more things
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用onNewIntent中的过滤项时,有时我会得到一个空指针异常.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
filtered.clear();
}
Run Code Online (Sandbox Code Playgroud)
怎么可能呢?
编辑:我的Activity的launchmode是SingleTask
编辑2:
我无法发送更多有用的日志,因为此崩溃正在生产中.只有我得到一些织物日志.
感谢您的帮助,但我无法粘贴整个代码隐私的原因.
我认为我在SingleTask-OnCreate-OnNewIntent使用方面存在问题.我只是试图通过通知打开我的应用程序,并通过参数决定当用户导航到活动时将打开哪个片段.
你有任何关于这个包含SingleTask-OnCreate-OnNewIntent实现的例子吗?
感谢大家的帮助.
如您所知,将Android应用程序设计为模块是当今Android开发领域的流行做法之一.但这种趋势带来了一些挑战.其中之一是Circular Dependency.
例如,我有一个HomeActivity从Home Feature模块打开的导航模块.此外,我必须从产品模块中打开另一个活动,例如ProductListActivity.
如果我在以下活动之间导航,则主页功能必须包括导航模块和导航模块应包括HomeFeature:
val intent = Intent(activity, HomeActivity::class.java)
Run Code Online (Sandbox Code Playgroud)
这会引起circular dependency问题.
要找出解决此问题的最快解决方案,请按照以下方法创建意图并使用此方法构建导航系统.
Intent(Intent.ACTION_VIEW).setClassName(PACKAGE_NAME, className)
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,我们将通过这种导航方法解决其他可能的问题?还有其他做法来处理模块化Android应用程序中的导航吗?
当我尝试重建我的项目时,出现以下错误:
warning: flag is not supported by this version of the compiler: -Xallow-no-source-files
warning: flag is not supported by this version of the compiler: -Xjava-source-roots=/Users/tyln/AndroidStudioProjects/PhoneBox/base/navigation/build/generated/source/buildConfig/dev/debug
base/navigation/src/main/java/com/raqun/phonebox/navigation/IntentLoader.kt:7:9: error: unresolved reference: BuildConfig
BuildConfig.PACKAGE_NAME,
^
> Task :base:navigation:compileDevDebugKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':base:navigation:compileDevDebugKotlin'.
> Compilation error. See log for more details
Run Code Online (Sandbox Code Playgroud)
当我检查课程时,没有未解析的引用。
我正在使用 Gradle 版本3.3.1
我几乎尝试了诸如Invalidate Cache / Restart, Clean and Rebuild, Close and Reopen project, Reimport project, delete idea …
我正在努力支持阿拉伯语。当我使用以下代码更改应用程序中的语言时(请参阅下文),在大多数设备中它工作正常,但在某些设备(例如Galaxy S7, Galaxy S8, LG G5UI 转换为RTL成功)但未加载阿拉伯语资源并且应用程序仍使用EN字符串资源.
有没有人对这个问题有任何意见?感谢您的回答。
这是我用于更改语言的代码:
private fun updateResources(context: Context, locale: Locale): Context {
Locale.setDefault(locale)
val res = context.resources
val config = res.configuration
config.setLocale(locale)
config.setLayoutDirection(locale)
BaseActivity.setLayoutDirection(res.configuration.layoutDirection)
Session.lang = locale.language
return context.createConfigurationContext(config)
}
Run Code Online (Sandbox Code Playgroud) 我使用的是Dagger 2.11带Kotlin.一切都很好,Dagger但当我ContributesAndroidInjector向项目添加注释时,我收到此错误:
e:
...build/tmp/kapt3/stubs/devDebug/com/raqun/android/di/AppComponent.java:6: error: dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
e:
e: public abstract interface AppComponent extends dagger.android.AndroidInjector<MyApp> {
e:
Run Code Online (Sandbox Code Playgroud)
这是我使用的依赖项:
$rootProject.ext.daggerVersion = 2.11
compile "com.google.dagger:dagger-android:$rootProject.ext.daggerVersion"
compile "com.google.dagger:dagger-android-support:$rootProject.ext.daggerVersion"
kapt "com.google.dagger:dagger-compiler:$rootProject.ext.daggerVersion"
annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.ext.daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.ext.daggerVersion"
Run Code Online (Sandbox Code Playgroud)
我已添加:
kapt {
generateStubs = true
}
Run Code Online (Sandbox Code Playgroud)
和
apply plugin: 'kotlin-kapt'
Run Code Online (Sandbox Code Playgroud)
我错过了什么或做错了什么?谢谢你的帮助.
不是:我已经尝试过清理gradle和重建项目.
我正在尝试Recyclerview使用代码单击项目时完成适配器类的活动
public void onBindViewHolder(@NonNull CountryCodeAdapter.CountryViewHolder holder, int position{
CountryModel countryMode = countryModels.get(position);
final String cCode = countryModel.getName();
holder.llcountryCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(v.getContext(),RegisterActivity.class);
i.putExtra("countryCode", cCode);
v.getContext().startActivity(i);
((AppCompatActivity)context).finish();
}
}
}
Run Code Online (Sandbox Code Playgroud)
也尝试过这个但是没用
((Activity)context).finish();
Run Code Online (Sandbox Code Playgroud)
我得到这个错误:
cannot be cast to android.support.v7.app.AppCompatActivity
Run Code Online (Sandbox Code Playgroud)