天道酬勤,学无止境

Error: "Only the Kotlin standard library is allowed to use the 'kotlin' package"

I want to build my first kotlin project in Android studio 3.0.1 . but i got these 2 errors :

  1. Only the Kotlin standard library is allowed to use the 'kotlin' package .

  2. Error:Execution failed for task ':app:compileDebugKotlin'.

how can i use or add the Kotlin standard library?

manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="kotlin.amirreza.mykotlinproject">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    </manifest>

gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "kotlin.amirreza.mykotlinproject"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:0.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
}

评论

You set your package name to kotlin.

Change all package kotlin statements in your .kt files to something like package mykotlintest

It's possible to work around this issue by adding the -Xallow-kotlin-package argument when kotlinc is invoked, that's what Kotlin does to build itself. But changing the package name is a cleaner solution.

As error says :

Only the Kotlin standard library is allowed to use the 'kotlin' package

You can not use 'kotlin' for your package name and your Package (applicationId) is :

kotlin.amirreza.mykotlinproject

So you must change it to something else with renaming or creating new applicaton with another package name

As @EmmanuelBourg correctly mentioned, below there is some code to do this

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions.freeCompilerArgs += ["-Xallow-kotlin-package"]
}

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Error while porting app from Eclipse to Android Studio
    I am in the process of porting a project from Eclipse to the latest Android Studio. All went fine by copying all the files in the directory used by AS but I get a host of errors practically on all the libraries I use and the imports from my own project: what may be the problem? This is the list of errors: (of course the unfound symbols are fine and kicking in the project). /Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/LoginActivity.java Error:(10, 30) error: package com.google.android.gcm does not exist Error:(29, 73) error: interface
  • 将应用程序从 Eclipse 移植到 Android Studio 时出错(Error while porting app from Eclipse to Android Studio)
    问题 我正在将项目从 Eclipse 移植到最新的 Android Studio。 通过复制 AS 使用的目录中的所有文件,一切顺利,但实际上我使用的所有库和我自己项目的导入都出现了许多错误:可能是什么问题? 这是错误列表:(当然,未找到的符号很好并且在项目中起作用)。 /Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/LoginActivity.java Error:(10, 30) error: package com.google.android.gcm does not exist Error:(29, 73) error: interface expected here /Users/fbartolom/Documents/Android/TaxiProfessional/app/src/main/java/info.inarrivo.taxiprofessional/NearStatus.java Error:(8, 33) error: cannot find symbol class BookingStatus Error:(8, 58) error: cannot find symbol class
  • MySQL错误提示语句及翻译——详情请看我免费分享的文件
    一者、礼敬诸佛。二者、称赞如来。三者、广修供养。四者、忏悔业障。五者、随喜功德。六者、请转法輪。七者、请佛住世。八者、常随佛学。九者、恒顺众生。十者、普皆回向。添加链接描述 OS error code 1: Operation not permitted 操作系统错误代码1:不允许进行操作 操作系统错误代码1:不允许操作 OS error code 2: No such file or directory 操作系统错误代码2:无此类文件或目录 操作系统错误代码2:没有这样的文件或目录 OS error code 3: No such process 操作系统错误代码3:没有这样的过程 操作系统错误代码3:没有这样的进程 OS error code 4: Interrupted system call 操作系统错误代码4:系统调用中断 操作系统错误代码4:系统调用中断 OS error code 5: Input/output error 操作系统错误代码5:输入/输出错误 操作系统错误代码5:输入/输出错误 OS error code 6: No such device or address 操作系统错误代码6:无此类设备或地址 操作系统错误代码6:没有这样的设备或地址 OS error code 7: Argument list too long 操作系统错误代码7:参数列表过长
  • std::error_code, my_error::check_block == my_error::validate && my_error::accept_block == my_error::validate(std::error_code, my_error::check_block == my_error::validate && my_error::accept_block == my_error::validate)
    问题 我正在使用 std::error_code 并定义了一堆错误(使用枚举类)并注册。 我现在有一个非常通用的错误,称为 my_error::validate,但想在我的库中提供更具体的版本。 通常人们会想要使用: if (ec == bc::error::validate) // ... 然而,有时他们可能希望查看与该 std::error_code 相关的特定错误或打印错误消息。 // ec.message() says "check_block() failed to do XYZ" assert(ec == bc::error::check_block); 我希望能够启用类似的功能: if (ec == bc::error::validate) { if (ec == bc::error::check_block) // bc::error::check_block is a more specific case of bc::error::validate } 似乎我可以以某种方式使用类别或条件? 如何在不需要定义一大堆新错误枚举的情况下做到这一点? 这是一个库,因此该库的用户不得不使用 bc::generic_error::validate 和 bc::error::check_block 会很痛苦。 代码如下: #include <system_error>
  • how to get series of requests in ibapi on python
    I am new both in Python and ibapi, I have ask Interactive Broker itself, they told me only : The self.done is originally defined in the parent class EClient that is used to indicate the current API connection is "done". You should not use it as an indicator to stop a loop that is build by yourself. You can keep one API client connection live until you have finished downloaded all the historical data you need. If you need to slow down the pace in requesting data, you can use other thread control in python, such as the sleep() function, to add more wait time in your loop so it does not send
  • SysErrorMessage 函数和系统错误信息表
    SysErrorMessage 函数和系统错误信息表 在看 API 文档时, 我们经常见到 GetLastError; 它可以返回操作后系统给的提示. 但 GetLastError 返回的只是一个信息代码, 如何返回对应的具体信息呢? FormatMessage 可以, 但这个函数太复杂了; 可以用 SysErrorMessage 代替它. 举例:var err: string; begin err := SysErrorMessage(ERROR_INVALID_HANDLE); ShowMessage(err); {句柄无效。} end; 下面就是用 SysErrorMessage 获取的部分系统错误信息表:信息常数 常数值 对应信息 ERROR_SUCCESS 0 操作成功完成。 NO_ERROR 0 操作成功完成。 ERROR_INVALID_FUNCTION 1 函数不正确。 ERROR_FILE_NOT_FOUND 2 系统找不到指定的文件。 ERROR_PATH_NOT_FOUND 3 系统找不到指定的路径。 ERROR_TOO_MANY_OPEN_FILES 4 系统无法打开文件。 ERROR_ACCESS_DENIED 5 拒绝访问。 ERROR_INVALID_HANDLE 6 句柄无效。 ERROR_ARENA_TRASHED 7 存储控制块被损坏。
  • Compiling error in C++ project with C and C++ codes
    I've created a C++ project where I use C and C++ codes and have some problems with headers... OK, I have 3 codes: basicOCR.cpp #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "preprocessing.h" #include "basicOCR.h" preprocessing.c #include <stdio.h> #include <ctype.h> #include <math.h> #include "preprocessing.h" main.c #include <stdio.h> #include <ctype.h> #include "basicOCR.h" and my 2 own header files: basicOCR.h #include <stdio.h> #include <ctype.h> preprocessing.h #include <stdio.h> #include <ctype.h> Whenever I try to compile a project, it compiles basicOCR.cpp without
  • Grails 2.3.7 error when creating a new project
    I just a fresh install: I downloaded and installed JDK and GGTS. I then created a new Grails 2.3.7 project and I get the error message below. Is this a known issue or am I doing something wrong? Command terminated with an exception: java.lang.Exception (see details for partial output) Command: GrailsCommand(P/MangaReader> compile --non-interactive --refresh-dependencies) ---- System.out ---- Loading Grails 2.3.7 . |Environment set to development .......... |Compiling 79 source files .Error | Compilation error: startup failed: C:\Users\\Documents\workspace-ggts-3.5.0.RELEASE\MangaReader\target
  • Build failed with cstdio and cstdlib errors in visual C++
    Errors: 1>------ Build started: Project: alglibTest, Configuration: Debug Win32 ------ 1>Build started 5/22/2011 12:52:26 PM. 1>InitializeBuildStatus: 1> Touching "Debug\alglibTest.unsuccessfulbuild". 1>ClCompile: 1> main.cpp 1>c:\program files\microsoft visual studio 10.0\vc\include\cstdio(38): error C2054: expected '(' to follow 'using' 1>c:\program files\microsoft visual studio 10.0\vc\include\cstdio(40): error C2061: syntax error : identifier 'using' 1>c:\program files\microsoft visual studio 10.0\vc\include\cstdio(40): error C2054: expected '(' to follow 'using' 1>c:\program files
  • includes <cstring> or <string> rises compile errors
    Have simple console application that builds fine: #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } It alsow builds fine if I add line #include <cstring> (or (and) #include <string>) #include <cstring> #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } If I add file gc.c just with only one include line ,#include <cstring> (or (and) #include <string>), compiler generates a lot of errors: Error 2 error C2061: syntax error : identifier 'using' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring 18 1 cstringerr Error 43 error C2061
  • 构建失败,在 Visual C++ 中出现 cstdio 和 cstdlib 错误(Build failed with cstdio and cstdlib errors in visual C++)
    问题 错误: 1>------ Build started: Project: alglibTest, Configuration: Debug Win32 ------ 1>Build started 5/22/2011 12:52:26 PM. 1>InitializeBuildStatus: 1> Touching "Debug\alglibTest.unsuccessfulbuild". 1>ClCompile: 1> main.cpp 1>c:\program files\microsoft visual studio 10.0\vc\include\cstdio(38): error C2054: expected '(' to follow 'using' 1>c:\program files\microsoft visual studio 10.0\vc\include\cstdio(40): error C2061: syntax error : identifier 'using' 1>c:\program files\microsoft visual studio 10.0\vc\include\cstdio(40): error C2054: expected '(' to follow 'using' 1>c:\program files
  • 包括或者出现编译错误(includes <cstring> or <string> rises compile errors)
    问题 具有构建良好的简单控制台应用程序: #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } 如果我添加行#include <cstring> (或(和) #include <string> ),它也可以很好地构建 #include <cstring> #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } 如果我添加文件gc.c只包含一个包含行#include <cstring> (或(和) #include <string> ),编译器会生成很多错误: Error 2 error C2061: syntax error : identifier 'using' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring 18 1 cstringerr Error 43 error C2061: syntax error : identifier 'strxfrm' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring 26 1
  • 创建新项目时出现 Grails 2.3.7 错误(Grails 2.3.7 error when creating a new project)
    问题 我只是全新安装:我下载并安装了 JDK 和 GGTS。 然后我创建了一个新的 Grails 2.3.7 项目,并收到以下错误消息。 这是一个已知问题还是我做错了什么? 命令以异常终止:java.lang.Exception(请参阅部分输出的详细信息)命令:GrailsCommand(P/MangaReader> compile --non-interactive --refresh-dependencies) ---- System.out ---- Loading圣杯 2.3.7 。 |环境设置为开发....... |编译79个源文件.Error | 编译错误:启动失败:C:\Users\\Documents\workspace-ggts-3.5.0.RELEASE\MangaReader\target\work\plugins\database-migration-1.3.8\grails-app\controllers\grails\plugin\ databasemigration\DbdocController.groovy:-1:“grails.plugin.databasemigration.DbdocController”类中方法“java.lang.Object withFormat(groovy.lang.Closure)”的重复方法名称/签名。 @ 行
  • Can not build war from grails project
    I'm building Grails (2.4.4) project and I faced very strange problem: I can 'run-app', I can 'compile' it but I can not 'war' or 'run-war' it. There is a problem with Enum class (AlertType) from src/groovy directory when importing it to domain class (Alert): | Compiling 258 GSP files for package [myProject]. | Error WAR packaging error: startup failed: file:/home/me/workspaces/workspaceGrails/myProject/grails-app/domain/com/example/alert/Alert.groovy: 4: unable to resolve class com.example.alert.AlertType @ line 4, column 1. import com.example.alert.AlertType Like I said: project is running in
  • 无法从 grails 项目构建战争(Can not build war from grails project)
    问题 我正在构建 Grails (2.4.4) 项目,但我遇到了非常奇怪的问题:我可以“运行应用程序”,我可以“编译”它,但我不能“战争”或“运行战争”它。 src/groovy 目录下的 Enum 类 (AlertType) 导入域类 (Alert) 时出现问题: | Compiling 258 GSP files for package [myProject]. | Error WAR packaging error: startup failed: file:/home/me/workspaces/workspaceGrails/myProject/grails-app/domain/com/example/alert/Alert.groovy: 4: unable to resolve class com.example.alert.AlertType @ line 4, column 1. import com.example.alert.AlertType 就像我说的:项目正在开发环境中运行,但我无法构建战争并将其投入生产。 这是来自 src/groovy/com/example/alert 的 AlertType 代码: package com.example.alert public enum AlertType { NORMAL, INSPECTION
  • g++ 4.6.1 编译器错误:错误:未知伪操作:`.cfi_personality'(g++ 4.6.1 compiler error: Error: unknown pseudo-op: `.cfi_personality')
    问题 我有一个文件,它在我的 macbook pro 上使用 g++ (4.6.1) 运行 osx (snow leopard) 编译时没有错误或警告。 我刚刚将它上传到我们的 linux 集群(不是由我运行)并尝试在那里编译(也使用 gcc 4.6.1)。 这次我与汇编程序出现了许多奇怪的错误消息。 如何解释以下错误? g++ -I../shared/boost_1_47_0 -std=c++0x -O2 -c ../shared/ft.cpp -o ../shared/ft.o /tmp/ccEqihNa.s: Assembler messages: /tmp/ccEqihNa.s:809: Error: unknown pseudo-op: `.cfi_personality' /tmp/ccEqihNa.s:810: Error: unknown pseudo-op: `.cfi_lsda' /tmp/ccEqihNa.s:1055: Error: unknown pseudo-op: `.cfi_personality' /tmp/ccEqihNa.s:1056: Error: unknown pseudo-op: `.cfi_lsda' :145: Error: unknown pseudo-op: `.cfi_personality' :146: Error
  • “Can not set org.eclipse.aether.spi.log.Logger” with custom maven plugin
    I have written a small custom maven plugin, and it runs fine.. most of the time. When using it, it's configured to run on test phase, and I see it executing, no problem. Now problem comes later, when I do mvn clean install or mvn clean deploy in the project using the plugin : it fails with a message I can't make sense of. And it clearly comes from my plugin, because if I remove it, then mvn clean install works. Error message is very long and it has 4 similar traces as the one below. I am quite clueless with where it can come from.. any idea ? Error injecting: private org.eclipse.aether.spi.log
  • AppCompat v7 r21 returning error in values.xml?
    I'm using Android Studio and when I add compile "com.android.support:appcompat-v7:21.0.0" to my Gradle file, I'm getting a ton of errors: C:\Users\WindowsSucks\AndroidStudioProjects\MMMeds\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.0\res\values-v11\values.xml Error:(36, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'. Error:(36, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'. Error:(36, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'
  • Why am i getting Unresolved dependencies path: org.scala-sbt:compiler-bridge_2.12:1.0.3
    I'm trying to start project in intelij idea by this tutorial, but when i'm running my project i'm getting this warn and error Here's logs: [info] Loading settings from idea.sbt ... [info] Loading global plugins from /root/.sbt/1.0/plugins [info] Updating {file:/root/.sbt/1.0/plugins/}global-plugins... Waiting for lock on /root/.ivy2/.sbt.ivy.lock to be available... [info] Done updating. [info] Loading settings from plugins.sbt ... [info] Loading project definition from /home/r/Документы/sbtExampleProject/project [info] Updating {file:/home/r/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1
  • tomcat-maven-plugin using Tomcat 7 - tomcat:deploy works, tomcat:undeploy doesn't
    I have a working configuration for tomcat:deploy, but when I come to undeploy the WAR, I get the following error which has left me foxed: [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com:DocBookScratchProject:war:0.1.0.BUILD-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.codehaus.mojo:tomcat-maven-plugin is missing. @ line 166, column 12 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven