小编Sol*_*oul的帖子

build.gradle文件中的compileKotlin块抛出错误"找不到参数[...]的方法compileKotlin()"

我正在尝试将Kotlin配置为在我的Android项目中使用Java 1.8.我已经尝试compileKotlin在我的build.gradle文件底部添加块,但如果我这样做,我会收到错误.

发生的错误如下:

错误:(38,0)无法在类型为org.gradle.api.Project的项目':core'上找到参数[build_dvcqiof5pov8xt8flfud06cm3 $ _run_closure4 @ 66047120]的方法compileKotlin().

没有这个块,项目运行良好.我错过了什么?这是完整的build.gradle文件,它是非常基本的东西:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'


android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'


    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 25
        versionCode 1
        versionName '1.0.0'

        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    compile 'com.google.android.support:wearable:2.0.2'
}

repositories {
    mavenCentral()
}

compileKotlin {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    kotlinOptions {
        jvmTarget = '1.8'
        apiVersion = …
Run Code Online (Sandbox Code Playgroud)

android gradle kotlin

43
推荐指数
4
解决办法
9832
查看次数

什么是警告的原因"指针缺少可空性类型说明符"?

+ (UIColor*) getColorWithHexa(NSString*)hexString;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述:

这是我班上的方法定义.这引起了警告.什么是类似警告的原因以及如何解决这些问题?

我正在返回一个UIColor对象,而该问题与块有关,在注释中给出.

所以,它很有帮助.

ios objective-c-nullability

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

Lottie Android:为动画添加颜色叠加

我正在使用Lottie for Android在应用中添加一些动画.在此应用程序中,可以通过设置选择主色和强调色.我正在使用具有透明背景的动画.为了使动画适合所选择的颜色,我想为动画添加颜色叠加,这样我可以有一个动画文件,但我可以通过编程方式设置颜色.

有没有人知道如何通过添加颜色叠加来操纵动画?

animation android lottie-android

6
推荐指数
3
解决办法
7155
查看次数

Laravel 使用自定义命名空间扩展 Illuminate\Foundation\Testing\TestCase

我正在尝试为我的 Laravel (5.2) API 项目设置单元测试。在使用单元测试之前,我想为它们定义一个自定义命名空间,因此我namespace Test;在默认TestCase.php文件中创建了 。就像这样:

namespace Test;

class TestCase extends Illuminate\Foundation\Testing\TestCase
{
  ...
}
Run Code Online (Sandbox Code Playgroud)

然后我UnitTests在该tests文件夹下创建了一个文件夹,并将单元测试放入该文件夹中,命名空间如下:

namespace Test\UnitTests;

use Test\TestCase;

class CreateAccountTest extends TestCase
{
  ...
}
Run Code Online (Sandbox Code Playgroud)

现在,当我想运行单元测试时,出现以下错误:

PHP Fatal error: Class 'Test\Illuminate\Foundation\Testing\TestCase' not found in /var/www/ops/tests/TestCase.php on line 6

所以基本上,Laravel 认为该类Illuminate\Foundation\Testing\TestCase是在 Test 命名空间中找到的,而不是IlluminateLaravel 的命名空间中。

我还在文件中配置了以下自动加载composer.json

"autoload": {
    "classmap": [
        "database",
        "tests"
    ],
    "psr-4": {
        "App\\": "app/",
        "Test\\": "tests/"
    }
},
"autoload-dev": {
    "classmap": [ …
Run Code Online (Sandbox Code Playgroud)

php phpunit laravel laravel-5

5
推荐指数
1
解决办法
1042
查看次数

Laravel 5.2单元测试错误:BadMethodCallException:调用未定义的方法Illuminate \ Database \ Query \ Builder :: make()

我正在尝试使用Laravel 5.2设置PHPunit。我按照文档进行了简单的单元测试,但是每个测试都会引发相同的错误:

1)CreateAccountTest :: testCreateUserWithInvalidEmail BadMethodCallException:调用未定义的方法Illuminate \ Database \ Query \ Builder :: make()

/some/path/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2405 /some/path/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1426 / some /path/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3526 /some/path/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:504 / some /path/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:504 /some/path/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:73 /some/path/tests/UnitTests/CreateAccountTest.php:32

我的单元测试看起来都与此类似,只是每次都声明一个不同的属性:

class CreateAccountTest extends TestCase
{

    protected $body;
    protected $app;

    protected function setUp() {
        parent::setUp();

        $this->app = factory(\App\Models\App::class)->create([
           'name' => 'Test Suite'
       ]);

        $this->body = [
            'name' => 'Doe',
            'firstName' => 'John',
            'login' => 'john.doe',
            'email' => 'john.doe@johndoe.com',
            'password' => 'test1324',
            'repeatPassword' => 'test1234',
            'appId' => $this->app->id
        ];
    }

    public function testCreateUserWithInvalidEmail() {
        $this->body['email'] = …
Run Code Online (Sandbox Code Playgroud)

php phpunit laravel laravel-5.2

5
推荐指数
1
解决办法
1377
查看次数

继承自 AppCompat Toolbar 更改工具栏图标边距

在我的项目中,我正在扩展android.support.v7.widget.Toolbar以向该类添加一些额外的功能。但是,当我在布局文件中实现此类时,它会更改工具栏上显示的图标的边距(或填充,不确定......)。

默认 android.support.v7.widget.Toolbar 结果:

android.support.v7.widget.Toolbar

自定义工具栏类结果:

自定义工具栏

我的自定义工具栏类还没有额外的代码,它只是实现了所需的构造函数,因此我自己不操作边距。

这是自定义工具栏类:

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;


public class ThemedToolbar extends Toolbar {

    public ThemedToolbar(Context context) {
        this(context, null);
    }

    public ThemedToolbar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ThemedToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我在所有活动中包含的工具栏布局文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="?actionBarSize">

    <com.endare.ui.theme.view.ThemedToolbar
        android:id="@+id/toolbar_control"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white" />

    <RelativeLayout
        android:id="@+id/toolbar_content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/toolbar_logo"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:layout_marginBottom="5dp" …
Run Code Online (Sandbox Code Playgroud)

android android-toolbar

4
推荐指数
1
解决办法
417
查看次数