I've implemented the new experimental build tools (gradle-experimental:0.2.1) for an app with many modules, but the current api is pretty awful and incompatible with certain libraries.
I'm curious if it's possible to pull all ndk code into a module and only process the ndk module with the experimental build tool and use the official build tools for the rest of the app. It'd be great to segregate all the experimental headaches into a small module.
I've tried a few things, but always ended up with gradle sync errors. Couldn't find anything online regarding whether this was feasible.
Part of my problem was an issue in the upgrade to AS 2.0. After fixing that issue I was able to do a quick test with the Hello World template project. I added a module and modified it to use the experimental plugin.
build.gradle (ndk module)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle-experimental:0.4.0"
}
}
dependencies {
repositories {
jcenter()
}
}
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 11
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "1"
}
}
}
Summary Update
I managed to get it working with ndk in a much more complicated project.
Here are the four primary requisites to get it working:
plugin gradle-experimental:0.4.0+ in your ndk module build.gradle (also convert to the new DSL)
plugin gradle:1.5.0 in your project build.gradle
Gradle 2.8 (gradle:1.5.0 plugin requires it)
Remove all jni from your main project (moved to module) since it's deprecated in 1.3.0+.
Without the combination of those versions of the gradle plugins I had lots of errors. Bit of a headache working out the kinks, but now I've segregated my ndk headaches to a simple module and I can integrate things like crashlytics that don't play well with gradle-experimental.
Related
I am trying to build a template of a Multiplatform library module in Android studio that can interoperate seamlessly with other normal Android library and application modules. I've found it's easy enough to make a Multiplatform Android project technically work in terms of compiling, running and publishing artefacts, but one problem I can't seem to solve is getting the source sets to show correctly in the Android project files pane view.
So you can see in the Project view here, the sources are divided into android, native and common directories and their respective test directories, for a total of six source directories:
In the Android Project view this is rendered by build targets instead of source file directories, so that this 'typing-sdk' module example has total of 10 different sub-modules. And you'll notice androidMain and androidTest are not among them: instead of being rendered as submodules, their sources fall under an inline kotlin directory instead; you can see the main and test com.demo.typing packages respectively.
It is a little annoying that every single build target gets its own submodule, when in practice, one will virtually never actually need to use some of these, like 'iosArm64Test' for example. Nevertheless, I can live with redundant submodules. The central problem here is that each of these submodules are populated with the wrong source files.
So whereas in the file structure, both the common and native sets have their own source files, as you can seen here:
In the Android Project View, every single submodule contains the Android sources!?
Either this is a bug in how Android Studio interoperates with the Kotlin Multiplatform Gradle Plugin, or there's something wrong with the Gradle build file I have written, which is this (using Gradle 7.1):
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.6.10'
id 'com.android.library' version '7.0.4'
}
allprojects {
group = 'typing'
version = '1.0'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
google()
}
}
kotlin {
android()
ios()
sourceSets {
commonMain
commonTest
androidMain {
dependsOn(commonMain)
}
androidAndroidTestRelease
androidTest {
dependsOn(commonTest)
dependsOn(androidAndroidTestRelease)
}
nativeMain {
dependsOn(commonMain)
}
nativeTest {
dependsOn(commonTest)
}
iosMain {
dependsOn(nativeMain)
iosX64Main.dependsOn(it)
iosArm64Main.dependsOn(it)
}
iosTest {
dependsOn(nativeTest)
iosX64Test.dependsOn(it)
iosArm64Test.dependsOn(it)
}
}
}
android {
compileSdk 31
defaultConfig {
minSdk 23
targetSdk 30
}
}
I have noticed most of the source examples already out there are using Kotlin DSL, which is preferable, but circumstances are forcing me to use Groovy here. On another project I have that is Kotlin DSL, using earlier versions of the Gradle (7.0.2) Android Gradle Plugin (7.0.2) and Kotlin (1.5.20), the Android project view is rendered differently, and though still quite defective, it's not so disastrously wrong as to have Android sources listed under every single build target module. In the Android block on that project you have a second definition of the sourcesets to the com.android.library plugin:
android {
compileSdk = 31
defaultConfig {
minSdk = 23
targetSdk = 30
consumerProguardFiles("proguard-rules.pro")
}
sourceSets.all {
java.srcDirs(file("src/android${name.capitalize()}/kotlin"))
res.srcDirs(file("src/android${name.capitalize()}/res"))
resources.srcDirs(file("src/android${name.capitalize()}/resources"))
manifest.srcFile(file("src/android${name.capitalize()}/AndroidManifest.xml"))
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
I don't know how to directly translate this into Groovy, but following the Android documentation, one can put something like this:
android {
compileSdk 31
defaultConfig {
minSdk 23
targetSdk 30
}
sourceSets {
main {
java.srcDirs = ['src/androidMain/kotlin']
manifest.srcFile 'src/androidMain/AndroidManifest.xml'
}
test {
java.srcDirs = ['src/androidTest/kotlin']
}
androidTest {
setRoot 'src/androidTest/kotlin'
}
}
}
Unfortunately this doesn't solve the problem. If nobody can show me workable Gradle scripts that don't create hideous and broken source file views in Android Studio, I will submit this as a bug to JetBrains.
IntellIJ is the recommended IDE to use when it comes to Multiplatform development.
Android Studio is for more Android Specific things, I don't think Android project view is something JetBrains wants to support, maybe there will be a Kotlin Multiplatform Project View at some point, but not at the moment.
(If you open a Spring, NodeJS, iOS or any other type of project the Android Project View will similarly seem broken)
Trying to start a new Kotlin project with Android Studio 3.0 Canary 1 displays this error. Full trace:
Error:Unable to find method
'com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;'.
Possible causes for this unexpected error include:Gradle's
dependency cache may be corrupt (this sometimes occurs after a network
connection timeout.) Re-download dependencies
and sync project (requires network)The state of a Gradle
build process (daemon) may be corrupt. Stopping all Gradle daemons may
solve this problem. Stop Gradle build
processes (requires restart)Your project may be using a
third-party plugin which is not compatible with the other plugins in
the project or the version of Gradle requested by the
project.In the case of corrupt Gradle processes, you can
also try closing the IDE and then killing all Java processes.
I've tried the first two options and the third-party plugins are left as default.
gradle-wrapper.properties
#Thu May 18 08:36:52 BST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.2-3'
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
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()
maven { url 'https://maven.google.com' }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I haven't touched any of these values myself, they're left as default. Creating a non-Kotlin new project does not have this problem.
In my build.gradle changing
ext.kotlin_version = '1.1.2-3'
to
ext.kotlin_version = '1.1.2-4'
fixed this.
You can find the most recent version here.
It worked for me
Using the 8.4.0 version
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
For Java
Just remove
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
downgrade butterknifeversion to 8.4.0
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
Don't forget to remove
apply plugin: 'me.tatarka.retrolambda'
from app level build gradle.
This is a known issue in Android Studio Preview 3.0:
If you see this error, it's possible you have a pre-existing version of the Kotlin plugin that is incompatible with the new Android Plugin for Gradle that's in Android Studio 3.0. The solution is to delete the old Kotlin plugin.
Open your project-level build.gradle file and locate ext.kotlin_version. It should be 1.1.2-4 (or higher). If it shows an older version, you need to delete the old Kotlin plugin so it does not obstruct the version included with Android Studio 3.0.
On Windows, it should be located at
C:\Users\user_name\AndroidStudio_version\config\plugins\Kotlin\
On Mac, look in
~/Library/Application\ Support/AndroidStudio_version/Kotlin/
In my case, the issue was caused because we were applying butterknife-gradle-plugin. Upgrading to 8.8.1 didn't fix the issue, but removing it certainly did.
The build.gradle belongs to the application, so I don't even know why we are using that plugin (I'm new to the project)
Update your kotlin version to the latest:
ext.kotlin_version = '1.1.2-4' //currently it's the latest version
Then you may face some more errors, so before syncing again, make sure that your buildToolsVersion is "26.0.2" or higher.
I downloaded the android studio 2.4 preview 6. It has support for java 8 without using jack. This is my application gradle filebuildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.4.0-alpha6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task wrapper(type: Wrapper) {
description 'Creates the gradle wrapper.'
gradleVersion '2.8'
}
And this is my gradle-wrapper.properties file
#Thu Apr 13 15:20:48 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip
But I keep getting the error :
Error:Unable to find method 'org.gradle.tooling.model.gradle.GradleBuild.getIncludedBuilds()Lorg/gradle/tooling/model/DomainObjectSet;'
What could be leading to the error and how can I solve it? I have tried invalidate cache/restart.
Everything looks fine to me. If you're going to use a beta build you shouldn't rely much on it for reasons like this; it's too buggy. Downgrade to the older version if you're going to push something to production or sell it, and if you're just looking at the new features, change to an older/newer preview. Android studio isn't known for being built that well.
Agree with Alex, I had mostly all the same versions as you:
Dependencies: Grade 2.4.0-alpha6
Gradle Wrapper: gradle-3.4.1-all.zip
Android Studio 2.4 preview 7
Had exactly the same error after updating from Android Studio 2.4 preview 1.
I got off the Canary channel and downloaded stable version 2.3.1 - Problem solved.
I might try a preview again in a couple months but I've found the last couple to be super buggy.
This project has been working for weeks. Yesterday, Android Studio pulled in some updates, and now gradle cannot find my play-services files. It has literally stopped building with no changes to the project - I didn't think this would happen with a gradle-based project.
gradle sync error
When I click on "Install Repository and sync project", another window opens with the message:
Ignoring unknown package filter 'extra-google-m2repository'Warning: The package filter removed all packages. There is nothing to install.
Please consider trying to update again without a package filter.
Here is my gradle file:
apply plugin: 'android-library'
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services-games:6.5+'
compile 'com.google.android.gms:play-services-plus:6.5+'
compile 'com.google.android.gms:play-services-appstate:6.5+'
}
android {
compileSdkVersion 20
buildToolsVersion '20'
}
Looking in my SDK manager, both "Google Repository" and "Android Support Repository" are installed.
SDK manager screen shot
It is possible that I have two different SDK's, but not sure how to tell if I do, and not sure how to remove the extra one if this is the issue.
Removing the "+" and specifying the specific version allows me to build again. I'm actually using 6.5.87, as 8.4.0 caused some other issue.
I am new to Android and I am about to deal with BLE app.
So I downloaded and installed the Android Studio 0.4.6 on Windows XP w SP3, and Updated it to 0.5.4.
Then, I went to http://developer.android.com/samples/index.html and downloaded the BluetoothLeGatt.zip (http://developer.android.com/downloads/samples/BluetoothLeGatt.zip) for my project.
When I tried "Import Project" to use the BluetoothLeGatt project, it failed with the message:
Failed to refresh Gradle project 'BluetoothLeGatt'
The project is using an unsupported version of Gradle. Please use version 1.10.
Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.)
Fix Gradle wrapper and re-import project Gradle settings
I clicked "Fix Gradle wrapper and re-import project Gradle settings" and got the message:
Quick Fix Failed
Unable to find any references to the Android Gradle plug-in in build.gradle files. Please click the link to perform a textual search and then update the build files manually.
The file build.gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
dependencies {
// Add the support lib that is appropriate for SDK 18
compile "com.android.support:support-v13:19.0.+"
}
// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
'main', // main sample code; look here for the interesting stuff.
'common', // components that are reused by multiple samples
'template'] // boilerplate code that is generated by the sample template process
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
sourceSets {
main {
dirs.each { dir ->
java.srcDirs "src/${dir}/java"
res.srcDirs "src/${dir}/res"
}
}
instrumentTest.setRoot('tests')
instrumentTest.java.srcDirs = ['tests/src']
}
}
Well, I am new in Android, so I don't know how to fix it, and I don't know what documents I should go through first that will help me to solve it.
Need help badly.
In build.gradle set your classpath to 0.9.+
classpath 'com.android.tools.build:gradle:0.9.+'
Then in gradle/wrapper/gradle-wrapper.properties you will need to check your distributionUrl The error is quite miss pointing making one belive that the problem is only within the build.gradle file.
Using gradle:0.9.+ your distributionUrl in gradle-wrapper.properties should be set to: http\://services.gradle.org/distributions/gradle-1.10-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
###Correct distributionUrl###
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
Then sync gradle, clean and rebuild project and you should be good to go