我的应用依赖于两个库.它们都使用相同的库' org.hamcrest:hamcrest-core ',但内部使用不同的版本.
androidTestCompile 'junit:junit:4.12' //(Depends on version 1.3)
androidTestCompile 'org.mockito:mockito-core:1.10.19' //(Depends on version 1.1)
Run Code Online (Sandbox Code Playgroud)
由于两个依赖项都相关Android instrumentation tests,因此应用程序构建成功,并在构建中包含更高版本 - 在本例中为1.3版.
但是,如果我将一个库用于主应用程序,而其他库用于Android Instrumentation测试,如下所示:
compile 'junit:junit:4.12'
androidTCompile 'org.mockito:mockito-core:1.10.19'
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.
:app:prepareDebugAndroidTestDependencies
Conflict with dependency 'org.hamcrest:hamcrest-core'. Resolved versions for app (1.3) and test app (1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:prepareDebugAndroidTestDependencies'.
> Dependency Error. See console for details.
Run Code Online (Sandbox Code Playgroud)
所以我去了例外中给出的链接.出现这种行为的原因如下
运行检测测试时,主APK和测试APK共享相同的类路径.如果主APK和测试APK使用相同的库(例如Guava)但是在不同版本中,Gradle构建将失败.如果gradle没有捕获到,那么您的应用程序在测试期间和正常运行期间可能会有不同的行为(包括其中一个案例中的崩溃).
到目前为止,我没有任何问题,但在以下情况下我遇到了问题:
1)在下面的声明中,只创建了一个主apk,因为本地单元测试在JVM上运行,那么为什么它会因冲突的相同例外而失败
compile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
Run Code Online (Sandbox Code Playgroud)
2)如果上述情况失败,那么这也应该失败.但令人惊讶的是,这种方法很好并且构建良好. …
这个问题已在这里提出,但它没有解决方案.
我有一个WebView.我想将最小高度设置为WebViewusing minHeight属性,但它不起作用.相同的属性适用于Button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.anshul.webview.WebActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="400dp"></WebView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:minHeight="150dp"
android:text="This is a Button. It's minHeight is set to 150 dp and it works !!"/>
Run Code Online (Sandbox Code Playgroud)
显然,从下图中,WebView不支持该minHeight属性.有谁知道这个问题的解决方案?
以下是我的场景。
我有Activity MainActivity一个FAB。当用户点击时FAB,我打开一个全屏DialogFragment。我想打开DialogFragment一些过渡。
这是我迄今为止尝试过的代码。
//MainActivity.java
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ReviewDialog reviewDialog = ReviewDialog.newInstance();
Slide slide = new Slide();
slide.setSlideEdge(Gravity.LEFT);
slide.setDuration(1000);
reviewDialog.setEnterTransition(slide);
Bundle bundle =ActivityOptions.makeSceneTransitionAnimation(ScrollingActivity.this)
.toBundle();
reviewDialog.setArguments(bundle);
reviewDialog.show(getSupportFragmentManager(),"review");
}
});
Run Code Online (Sandbox Code Playgroud)
这是 DialogFragment ReviewDialog 的代码。
//ReviewDialog.java
public class ReviewDialog extends DialogFragment {
static ReviewDialog newInstance() {
ReviewDialog f = new ReviewDialog();
// Supply num input as an argument.
Bundle args = …Run Code Online (Sandbox Code Playgroud) 注意:这个问题与这个问题不同,因为该问题没有给出答案解释如何取消我们对预加载图像所做的图像请求。
我有一个无限列表(RecyclerView)。我需要从 .txt 文件的最后一个绑定项目中预加载下一个“x”(读取 3)个项目的图像RecyclerView。另外,当某个特定对象Viewholder与窗口分离时,如果预加载图像请求尚未成功,我需要取消预加载图像请求。
我通过以下方式实现了它。
Map<Integer, SimpleTarget> simpleTargetMap = new HashMap<>();
public void preloadImage(int position, Context context, String imageUrl) {
SimpleTarget simpleTarget = new SimpleTarget() {
@Override
public void onResourceReady(@NonNull Object resource, @Nullable Transition transition) {
simpleTargetMap.remove(position);
}
};
Glide.with(context)asBitmap().load(imageUrl).into(simpleTarget);
simpleTargetMap.put(position, simpleTarget);
}
@Override
public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder) {
super.onViewDetachedFromWindow(holder);
SimpleTarget simpleTarget = simpleTargetMap.get(holder.getAdapterPosition());
Glide.with(context).clear(simpleTarget);
simpleTargetMap.remove(holder.getAdapterPosition());
}
Run Code Online (Sandbox Code Playgroud)
我能够达到预期的结果。但我用这种方法面临内存问题。如果我不使用预加载,我的内存使用量在 150-200 MB 之间。但如果我开始使用预加载,内存使用量会跃升至 250-300 mb。进行堆转储后,我看到很多位图对象,如果我不使用预加载,这些对象就不存在(没有那么多)。
那么在 Glide 中预加载图像的最佳方法是什么,这样我将来也可以取消图像请求呢?如果我不使用 SimpleTarget,有什么方法可以取消仅基于 imageUrl 的图像请求吗?
我有一个数据库,它有一个自定义数据类型FollowEntityType作为列。
@Entity(primaryKeys = arrayOf("id", "type"), tableName = "follow_info")
data class FollowInfoEntity(
@ColumnInfo(name = "id") var id: String,
@ColumnInfo(name = "type") var type: FollowEntityType,
)
Run Code Online (Sandbox Code Playgroud)
由于是自定义数据类型,所以我定义了一个类型转换器。
class FollowDatabaseTypeConverter {
@TypeConverter
fun toFollowEntity(entityType: String?): FollowEntityType? {
return FollowEntityType.from(entityType ?: Constants.EMPTY_STRING)
}
@TypeConverter
fun toString(entityType: FollowEntityType?): String? {
return entityType?.name
}
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,我能够在数据库中存储/检索值。但是,在其中一个查询中,构建失败。
这是查询。
@Query("select * from follow_info where type in (:entityTypeList)")
fun getFollowedEntitiesByType(entityTypeList: List<FollowEntityType>) : List<FollowInfoEntity>
Run Code Online (Sandbox Code Playgroud)
构建失败并出现以下错误。
Query method parameters should either be a type that can be converted into …Run Code Online (Sandbox Code Playgroud) 我有以下xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="100dp"
android:orientation="vertical"
android:background="#ff0000">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00ff00"
android:text="Button"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
它具有以下设计.
不应该button垂直放置在中心吗?我知道怎么layout_gravity和gravity工作.所以根据我的理解,按钮应该绝对位于水平和垂直的中心.
我在这里遇到一个非常奇怪的问题.在我fragment,我之后inflate的layout,findViewById()方法返回null的时候.但这个问题根本不可复制.我从Crashlytics获得这些崩溃报告.此次崩溃发生在其中一名QA成员身上,但之后他也无法重现此问题.
这是我片段的代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View customView= inflater.inflate(R.layout.custom_view, container, false);
ImageView back= (ImageView) customView.findViewById(R.id.back);
//Throwing Null Pointer Exception for the below line.
back.someFunc();
return customView;
}
Run Code Online (Sandbox Code Playgroud)
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/topics_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/default_background">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/back_to_top_margin_right"
android:layout_marginBottom="@dimen/back_to_top_margin_bottom"
android:src="@drawable/back"
android:visibility="gone"
android:id="@+id/back"/>
<LinearLayout
android:id="@+id/error_parent"
android:layout_width="match_parent"
android:background="?attr/default_background"
android:orientation="vertical"
android:layout_height="match_parent">
</LinearLayout>
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
崩溃日志
Fatal Exception: java.lang.RuntimeException: …Run Code Online (Sandbox Code Playgroud) android ×7
java ×2
android-room ×1
gradle ×1
kotlin ×1
picasso ×1
sqlite ×1
transition ×1
webview ×1