Tag: android studio

将Kotlin添加到现有Java项目会打破Android Studio gradle消息错误

我是Gradle和Android的新手,但是因为我已经把Kotlin添加到了我的项目中,所以我在Android Studio中遇到一个错误,我需要通过Gradle控制台,默认情况下不会给我任何好的堆栈跟踪或路径。 在现在出现错误的Gradle消息视图中,我只能得到 错误:执行任务’:app:kaptDebugKotlin’失败。 内部编译器错误。 查看日志了解更多详情 这是预期的function,因为它似乎在jetbrains示例项目中工作正常。 我的项目Gradle文件 buildscript { ext.kotlin_version = ‘1.1.4-2’ repositories { jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:2.3.3’ classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete […]

Gradle同步失败:无法findorg.jetbrains.kotlin(无意使用Kotlin)

(在我看来, 这个问题不是重复的) Android Studio中的错误消息: Gradle同步失败:无法findorg.jetbrains.kotlin:kotlin-stdlib:1.1.3-2 我不明白为什么Gradle不会在没有这个库的情况下同步,为什么Kotlin是强制性的。 另外,我还没有尝试或打算安装或使用Kotlin插件。 注意:刚刚在开发者更新频道上升级到最新的Android Canary版本之后就发生了这种情况。 没有问题或任何Kotlin在稳定版本或我的代码本身相关。

如何在我的Kotlin类中创建一个匿名接口实现并使用它?

我怎么能有这样的Kotlin的Java代码? 甚至IDE也不会完全将其转换为Kotlin! /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName className, IBinder service) { // We’ve bound to LocalService, cast the IBinder and get LocalService instance LocalBinder binder = (LocalBinder) service; mService = binder.getService(); mBound = true; } @Override public void onServiceDisconnected(ComponentName […]

将源文件附加到kotlin库项目不会显示在AS中

我想把源代码附加到一个kotlin库项目,看起来我成功了,因为我现在有了源代码jar: https://jitpack.io/com/github/walleth/kethereum/bip44/0.21/ 之前的版本没有出口的来源 – 所以我认为这是成功的。 https://jitpack.io/com/github/walleth/kethereum/bip44/0.20/ 不幸的是,AS不显示来源。 我是这样产生的: allprojects { repositories { jcenter() maven { url ‘https://jitpack.io’ } } apply plugin: “kotlin” apply plugin: “jacoco” apply plugin: “maven” apply plugin: “com.github.ben-manes.versions” dependencies { compile “org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version” testCompile ‘org.assertj:assertj-core:3.8.0’ testCompile ‘junit:junit:4.12’ } task sourcesJar(type: Jar, dependsOn: classes) { classifier = ‘sources’ from sourceSets.main.allSource } task javadocJar(type: Jar, […]

将android kotlin项目迁移到sdk 27

我想把我的android项目的targetSdkVersion从25改为27.问题是我使用了Kotlin,还有一些很大的改变: 1)改变了View.findViewById()的签名。 现在我需要使用findViewById 2)碎片的getContext()变得不是零安全,所以我需要添加! 到所有片段中的所有上下文值。 有没有办法自动修复整个项目? 这不是一个小项目,手动修复会花费很多时间。

在android studio中使用kotlin共享意图文本

我想共享文本在我的CardView使用共享意图使用KOTLIN,但有一个问题,最后一行代码在KOTLIN代码 val shareIntent = Intent() shareIntent.action = Intent.ACTION_SEND shareIntent.putExtra(Intent.EXTRA_STREAM, “ali”) shareIntent.type = “text/plain” startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))) 这是代码中的问题 startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))) 请帮帮我 看图像来理解我 图片 https://ibb.co/jQwYXw https://ibb.co/id0tXw https://ibb.co/fbCU5G 适配器完整的代码 class MyAdapter(context: Context, listItem: ArrayList) : RecyclerView.Adapter() { var Context = context var movieList = listItem; var layoutInflator = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MyViewHolder { var inflateView […]

Kotlin使用Gson将json字符串转换为ojbect列表

我有一个问题,Kotlin编写从json字符串转换为对象列表的代码。 在Java中通常是这样的: Gson gson = new Gson(); Type type = new TypeToken<List>() {}.getType(); List measurements = gson.fromJson(json, type); return measurements; 然而在Kotlin,当我尝试像这样: val gson = Gson() val type: Type = TypeToken<List>{}.type val measurements : List = gson.fromJson(text, type) return measurements IDE Android Studio强调为TypeToken所说的错误: 无法访问”:它是public / package / in’TypeToken’ 也强调说错误: types不匹配。 必需:键入! 发现:()→单位 那么有没有一种解决方案可以让Kotlin工作?

Android Studio和Kotlin – 不加载更改

要加载一个新的APK,我需要清理每一个建设之前。 这就像编译器没有注意到我的代码更改。 这是我的配置: 我的项目完全在Kotlin Kotlin版本1.1.60 Gradle版本4.4 Android构建工具版本3.1.0-alpha04 Android Studio 3.0(稳定) Java 8 数据绑定已启用 使用Kapt 即时运行被禁用 我还没有确认Java代码是否会显示相同的问题。 有没有人看过这个,find了解决办法?

Android Studio在第二次构建后显示Kotlin依赖警告

我刚刚在Android项目中启用了Kotlin,我偶然发现了一个警告。 在第二次构建之后(Build – > Rebuild Project),这个警告显示在Messages: Warning:Runtime JAR files in the classpath should have the same version. These files were found in the classpath: ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.2.10/85fe1811f3e586d0cc53aba1394d8089f1862215/kotlin-stdlib-jdk8-1.2.10.jar (version 1.2) ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.10/19bc012f8c4cd6b705bd6512263777cc19bcf259/kotlin-reflect-1.2.10.jar (version 1.2) /Applications/Android Studio.app/Contents/gradle/m2repository/org/jetbrains/kotlin/kotlin-stdlib-jre7/1.1.51/kotlin-stdlib-jre7-1.1.51.jar (version 1.1) ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.10/cfe8b616b3bf0811ef70863c86b745a2e767a66e/kotlin-stdlib-jdk7-1.2.10.jar (version 1.2) ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.10/b9bf650516989595a5390e5a54181e16347208ac/kotlin-stdlib-1.2.10.jar (version 1.2) 看起来第二个版本包含来自缓存的过时的kotlin-stdlib-jre7-1.1.51.jar 。 清洁构建(Build – > Clean Project)后,警告消失,下一个重建项目再次启动。 我正在使用Android Studio 3.0.1,并且明确地将Kotlin依赖包括在版本中: 的build.gradle buildscript { ext { […]

Android工作室kotlin插件错误

在Android工作室即时通讯错误: Plugin Error: Kotlin threw an uncaught AbstractMethodError. Disable Plugin 昨天一切都很好。 摇篮: buildscript { ext.kotlin_version = ‘1.1.51’ repositories { google() jcenter() mavenCentral() } dependencies { classpath ‘com.android.tools.build:gradle:3.0.1’ classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } Android工作室版本:3.0.1 Build#AI-171.4443003 更甚者:如果我用kotlin支持创建新的android项目失败,同样的错误。 #EDIT1 完整的根gradle构建脚本。 buildscript […]