小编Cyr*_*rus的帖子

在OS独立路径'META-INF/LICENSE'中找到多个文件

当我构建我的应用程序时,我得到了跟随错误.

错误:任务':app:transformResourcesWithMergeJavaResForDebug'的执行失败.在OS独立路径'META-INF/LICENSE'中找到多个文件

这是我的build.gradle文件

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "cn.sz.cyrus.kotlintest"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        javaCompileOptions{
            annotationProcessorOptions{
                includeCompileClasspath = true
            }
        }
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
 /*       exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'*/
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    }) …
Run Code Online (Sandbox Code Playgroud)

android gradle build.gradle

270
推荐指数
18
解决办法
21万
查看次数

预期 @HiltAndroidApp 具有值。您是否忘记应用 Gradle 插件?

我有谷歌这个问题,但结果对我不起作用。

详情如下。

    public final class App extends com.zhixin.wedeep.common.BaseApplication implements androidx.lifecycle.LifecycleOwner {
                 ^
     // Expected @HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin?

Run Code Online (Sandbox Code Playgroud)

应用程序代码。

@HiltAndroidApp
class App : BaseApplication(), LifecycleOwner {

    @Inject
    lateinit var service: EventService


    private val mLifecycleRegistry = LifecycleRegistry(this)

}


Run Code Online (Sandbox Code Playgroud)

此模块 gradle 文件。

apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-allopen'
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'dagger.hilt.android.plugin'

dependencies {
    implementation rootProject.ext.dependencies["hilt-android"]
    implementation rootProject.ext.dependencies["hilt-lifecycle-viewmodel"]
    kapt rootProject.ext.kapt["hilt-compiler"]
    kapt rootProject.ext.kapt["hilt-android-compiler"]
}
Run Code Online (Sandbox Code Playgroud)

谁有想法?谢谢!

android dagger-2 dagger-hilt

36
推荐指数
4
解决办法
7495
查看次数

尝试在空对象引用上调用接口方法“java.lang.Object kotlin.Lazy.getValue()”

抱歉我的愚蠢问题。

我有谷歌这个问题,但答案对我不起作用。

这是我的代码。

  data class Article(val id: Long, val title: String, val ingress: String, val image: String,
                       val dateTime: String, val tags: List<String>, val content: List<Item>, val created: Long, val changed: Long) {

        @delegate:Transient
        val formatDateString: String by lazy {
            val sdf = SimpleDateFormat("dd.MM.yyyy HH.mm")
            val date: Date = sdf.parse(dateTime)
            var time: String?
            if (date.year == Date().year) {
                time = SimpleDateFormat("dd MM,HH:mm", Locale.US).format(date)
            } else {
                time = SimpleDateFormat("dd MM yyyy,HH:mm", Locale.US).format(date)
            }
            time!!
        }

    }
Run Code Online (Sandbox Code Playgroud)

当我尝试获取formatDateString价值时,会发生上述异常。

代码访问 …

android kotlin

15
推荐指数
1
解决办法
1898
查看次数

当我使用lambda遍历String数组时,NoClassDefFoundError

当我使用lambda遍历String数组时,我得到了跟随错误.

java.lang.NoClassDefFoundError: com.twsz.app.ivybox.alarm.CreateOrUpdateAlarmActivity$$Lambda$1
at com.twsz.app.ivybox.alarm.CreateOrUpdateAlarmActivity.initView(CreateOrUpdateAlarmActivity.java:143)
at com.twsz.app.ivybox.alarm.CreateOrUpdateAlarmActivity.onCreate(CreateOrUpdateAlarmActivity.java:73)
Run Code Online (Sandbox Code Playgroud)

这是我的代码.我知道传统方式遍历String数组是可以的,但是为什么在使用lambda时会发生这种情况.

    String[] days = dayOfWeek.split(",");
    Arrays.asList(days).forEach(day->{
        int index = Integer.valueOf(day) -1;
        checkBoxList.get(index).setChecked(true);
    });//where happens NoClassDefFoundError
Run Code Online (Sandbox Code Playgroud)

我的build.gradle文件

   android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        defaultConfig {
            applicationId "com.twsz.app.ivybox"
            minSdkVersion 14
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
        }

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }

        dataBinding {
            enabled = true
        }
    }
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

java lambda android

14
推荐指数
3
解决办法
3022
查看次数

为什么异步网络调用的回调方法在活动结束后不会导致内存泄漏?

我们知道匿名内部类可能会导致内存泄漏.但是为什么它在异步网络调用时不起作用.
例如:

OkHttpClient client = new OkHttpClient();

 Request request = new Request.Builder()
                .get()
                .url(url)
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                // String str = response.body().string();
                // do sth to our View, but those views may be null when activity finished
                }

            }
        });
Run Code Online (Sandbox Code Playgroud)

我们将在回调方法调用时更改视图的状态,但这些视图在活动完成时始终为null.为什么这个用于回调的匿名内部类实例不会导致活动泄漏.

java android jvm okhttp

12
推荐指数
1
解决办法
889
查看次数

Hilt Fragments 必须附加到 @AndroidEntryPoint Activity。发现:类 androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity

运行单元测试代码时出现以下错误。

Caused by: java.lang.IllegalStateException: Hilt Fragments must be attached to an @AndroidEntryPoint Activity. Found: class androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity
at dagger.hilt.internal.Preconditions.checkState(Preconditions.java:83)
at dagger.hilt.android.internal.managers.FragmentComponentManager.createComponent(FragmentComponentManager.java:75)
at dagger.hilt.android.internal.managers.FragmentComponentManager.generatedComponent(FragmentComponentManager.java:63)
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.generatedComponent(Hilt_HomePage.java:70)
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.inject(Hilt_HomePage.java:89)
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.initializeComponentContext(Hilt_HomePage.java:53)
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.onAttach(Hilt_HomePage.java:45)
at androidx.fragment.app.Fragment.onAttach(Fragment.java:1602)
at com.zhixin.wedeep.homepage.ui.Hilt_HomePage.onAttach(Hilt_HomePage.java:35)
at com.zhixin.wedeep.homepage.ui.HomePage.onAttach(HomePage.kt:281)
Run Code Online (Sandbox Code Playgroud)

这是我的测试代码。

@HiltAndroidTest
@UninstallModules(HomePageDataModule::class)
@RunWith(AndroidJUnit4::class)
@LargeTest
class TestHomePageFragment {

    private val c = Composition("cyrus", "background", "description", "downloadUrl", "1000", "url", "1", true, "100", 100, "100", "test", "title", "1", "100", "cover", ArrayList(), "ONCE", null)

    @Inject
    lateinit var cpd: CompositionDao

    @get:Rule
    var hiltRule = HiltAndroidRule(this)




    @Before
    fun init() …
Run Code Online (Sandbox Code Playgroud)

android android-espresso dagger-hilt

10
推荐指数
3
解决办法
3780
查看次数

将数字格式化为字符串,不足两个字符时补0

我想将数字格式化为并在不足两个字符时String填充0

\n\n
fun formatDuration(val duration):String {\n    val minutes = duration.toInt() / 60\n    return  "$minutes"\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

例如,如果minutes是 6\xef\xbc\x8c,则应显示它06而不是6

\n

kotlin

9
推荐指数
2
解决办法
2657
查看次数

java.lang.AssertionError:活动永远不会成为请求状态

执行单元测试时出现以下错误

java.lang.AssertionError: Activity never becomes requested state "[CREATED, STARTED, RESUMED, DESTROYED]" (last lifecycle transition = "PRE_ON_CREATE")
at androidx.test.core.app.ActivityScenario.waitForActivityToBecomeAnyOf(ActivityScenario.java:338)
at androidx.test.core.app.ActivityScenario.launchInternal(ActivityScenario.java:272)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:238)
at androidx.test.ext.junit.rules.ActivityScenarioRule.lambda$new$3$ActivityScenarioRule(ActivityScenarioRule.java:98)
at androidx.test.ext.junit.rules.ActivityScenarioRule$$Lambda$3.get(Unknown Source:4)
at androidx.test.ext.junit.rules.ActivityScenarioRule.before(ActivityScenarioRule.java:103)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
Run Code Online (Sandbox Code Playgroud)

我的测试代码

@RunWith(AndroidJUnit4::class)
@LargeTest
class TestHomePageFragment {


    private val intent = Intent(ApplicationProvider.getApplicationContext(), AudioPlayerActivity::class.java).apply {
        flags = Intent.FLAG_ACTIVITY_NEW_TASK
        putExtra(HomePageArouterConstants.KEY_ID,"1")
    }
    @get:Rule
     val activityRule:ActivityScenarioRule<AudioPlayerActivity> = activityScenarioRule(intent)


    @Test
    fun testVote(){
//        Assert.assertEquals(1,1)
        val scenario = activityRule.scenario
        scenario.moveToState(Lifecycle.State.RESUMED)
        onView(withId(R.id.linear_layout_like)).perform(click())
    }

}
Run Code Online (Sandbox Code Playgroud)

谁有这个问题的想法?

android android-testing android-espresso

8
推荐指数
0
解决办法
1241
查看次数

Espresso:找不到与ID匹配的层次结构视图:android:id/home

当我运行我的测试用例时,我得到了例外.

android.support.test.espresso.NoMatchingViewException:找不到层次结构中的视图匹配:id:android:id/home

这是我的TestCase代码.

 public void nav_to_alarm_test(){
        onView(withId(R.id.navigation_notifications)).perform(click());
        onView(withId(R.id.rl_reminder)).perform(click());
        onView(withId(R.id.item_test)).perform(click());
        onView(withId(android.R.id.home)).perform(click());//throw exception here
        onView(withId(android.R.id.home)).perform(click());
    }
Run Code Online (Sandbox Code Playgroud)

这是android.R.id.home,属于ActionBar提供的按钮

 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
            case R.id.item_test:
                startActivityForResult(CreateOrUpdateReminderActivity.class,CMD_ADD_REMINDER);
                return true;
            default:
                return super.onOptionsItemSelected(item);

        }
    }
Run Code Online (Sandbox Code Playgroud)

为什么在资源ID android.R.id.home的层次结构中找不到视图?我有谷歌我的问题,但答案不是我想要的.
谢谢你的帮助.

android android-testing

6
推荐指数
1
解决办法
6503
查看次数

ConstraintLayout layout_constraintHorizo​​ntal_bias似乎不起作用

这是我的布局文件.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:hint="please input test content"
        android:inputType="phone"
        android:textColorHint="@android:color/holo_red_light"
        android:textSize="13sp"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintRight_toLeftOf="parent" />
    <TextView
        android:layout_width="80dp"
        android:layout_height="50dp"
        android:gravity="center"
        android:text="Hello"
        android:textColor="@android:color/black"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintHorizontal_bias="0.5" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

关注pic是预览视图.

在此输入图像描述

我想将TextView移动到center_horizo​​ntal到父视图,但layout_constraintHorizontal_bias=0.5"似乎不起作用.

谁有这个问题的想法?先谢谢!

android android-layout android-constraintlayout

6
推荐指数
2
解决办法
1万
查看次数