I'm trying to name the artifact that gets built by gradle. Look at this build.gradle:
archivesBaseName='this_is_ignored'
apply plugin: 'groovy'
archivesBaseName='this_is_also_ignored'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.+'
}
I also tried in gradle.properties:
archivesBaseName=`this_is_ignored_too`
In every case ./gradlew build generates a .jar file based on the folder where the project resides (which as I understand it is project.name, I was just hoping to override that with archivesBaseName).
In other words, I want:
~/gradle-helloworld > ./gradlew build
to generate this_is_ignored.jar, but it's generating gradle-helloworld.jar instead.
Any ideas?
(Turning Peter's comment into a CW answer.)
If you set archivesBaseName before applying the plugin, you'll introduce a dynamic property (which gives a deprecation warning). This dynamic property will then shadow the one introduced by the plugin, which is why the second assignment doesn't have the desired effect either. The solution is to only set the property after applying the plugin.
Related
I am working with Jetpack Compose and I came across "com.diffplug.spotless" plugin in the app's build.gradle file of many examples, but I am not sure if I need it in my project. Can anyone explain the purpose of using it in the Jetpack compose projects?
''' apply plugin: "com.diffplug.spotless" '''
Spotless: Keep your code spotless with Gradle
While working, Many a times you will get formatting issues at the stage of every commit like removing empty lines, cutting white spaces correct, indentation and other minor formatting mistakes.
Using tool/plugin called “Spotless” will reduce time in addressing code review comments.
Spotless provides support for a variety of languages.
Spotless consists of a list of format and each format has:-
1.a target (the files to format), which you set with target.
2.a list of FormatterStep, which are just String -> String functions, such as replace, replaceRegex, trimTrailingWhitespace, custom, prettier, eclipseWtp, licenseHeader etc.
To start integration with Gradle:-
1.Add the following dependency to your build.gradle file
classpath(“com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion”)
2.Apply the following plugin
apply plugin: ‘com.diffplug.gradle.spotless’
3.Applying spotless to your gradle file in Android Java source
spotless {
java {
// ...
target '**/*.java'
// ...
}
}
Note:- Be sure to add target '**/*.java' otherwise spotless will not detect Java code
inside Android modules.
For more detail you can refer this link : 1
Updated to Android Studio 3.0.0 with new android gradle plugin.
While buildin project got message:
What went wrong:
Execution failed for task `':app:externalNativeBuildDebug'`.
Expected output file at `gst-build-arm64-v8a/libgstreamer_android.so` for target `gstreamer_android` but there was none
but libgstreamer_android.so library file is already there. For native code I use ndk-build. Does anyone have this issue?
Add to build.gradle file of our android module field targets.
android {
defaultConfig {
externalNativeBuild {
ndkBuild {
targets "name_of_native_module_in_android_mk_file"
}
...
}
Don't add gstreamer_android.
UPDATE: Valery's answer works!
Obsolete answer:
That's not the perfect fix, it's just temporary until I have time to take a deep look into the problem. Downgrade your gradle plugin:
File -> Project Structure
Click at "Project"
At "Gradle version" field put:
3.3
At "Android Plugin Version" field put:
2.3.3
Hit "OK"
Accept the messages, sync the project, etc... Android Studio may prompt a windown asking for update gradle plugin again, just don't accept it for now...
I guess the update on gradle changed the way the builds are made, maybe something on Android.mk will have to change or some other parameter on build.grade...
edit: I found some clue at: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
API changes Android plugin 3.0.0 introduces API changes that removes
certain functionalities and may break your existing builds. Later
versions of the plugin may introduce new public APIs that replace
broken functionalities.
Modifying variant outputs at build time may not work Using the Variant
API to manipulate variant outputs is broken with the new plugin. It
still works for simple tasks, such as changing the APK name during
build time, as shown below:...
So, I guess we should keep using the temporary fix (not updated version of gradle)...
I would like to ask if it is possible to use libGDX particle effect tool if you didn't tick it on project setup at the beginning. I am using AndroidStudio.
Yes,
https://github.com/libgdx/libgdx/wiki/2D-Particle-Editor
You can also just open another project and run the particle editor from there since you can export your effects to anywhere you want and the ParticleEffect does not depend on anything in gdx.tools. Or you could simply import it with Gradle. Just add it to your desktop dependency and re-sync your project.
build.gradle:
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
}
I am writing a gradle build file. I want to use the dependency Apache Commons Net v3.3.
Now, whenever I type a statement that uses a class from this dependency, IntelliJ does not recognize that I am missing a import. I was aldo not offered any classes from the previously added dependency. I did indeed click the refresh button on the gradle tab in IntelliJ IDEA, before I added any dangling content to my buildscript.
When I run gradlew now (and it compiles the buildscript), I get a error about a unrecognized Symbol.
Can I do something to make IntelliJ report missing imports to me?
I can add the import by looking up the javadoc online any manually copy-pasting the class name into my buildscript, but I find that rather annoying and I think that such primitive tasks should be done by a IDE.
This is pretty much the exact example:
apply plugin: 'java'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'commons-net:commons-net:3.3'
}
}
task example << {
FTPClient ftp = new FTPClient() //IntelliJ does not complain about missing imports, neither did it have the correct class available in auto-completion
}
Install the gradle plugin (which it seems like you already have).
Go to the gradle tab on the right side of the IDE and click the wrench icon to get to gradle settings.
Check the box that says "Use auto-import"
I recently discovered this awesome feature about gradle productFlavors. I currently have 3 variants (staging, sandbox and production) and I can deploy one of the variants at a time using build variant panel.
Is there a way I can deploy all variants at a time?
Yes,
In Android Studio, open the "Gradle Tasks" tab, which is usually on the right. You will see many tasks that start with 'assemble', double click on one of those.
For example, double clicking on 'assembleRelease' will create all your release apks.
From the docs:
Building and Tasks
We previously saw that each Build Type creates its own assemble
task, but that Build Variants are a combination of Build Type and
Product Flavor.
When Product Flavors are used, more assemble-type tasks are created.
These are:
1) assemble[Variant Name]
2) assemble[Build Type Name]
3) assemble[Product Flavor Name]
1) allows directly building a single variant. For instance
assembleFlavor1Debug.
2) allows building all APKs for a given Build Type. For instance
assembleDebug will build both Flavor1Debug and Flavor2Debug variants.
3) allows building all APKs for a given flavor. For instance
assembleFlavor1 will build both Flavor1Debug and Flavor1Release
variants.
The task assemble will build all possible variants.
If you know the names of the gradle tasks that install your variants you can run this from the root of your project in the terminal:
./gradlew install{VariantName1, VariantName2, VariantName3}Debug
This assumes you have a module build.gradle file with variants set up according to the guide. So something along these lines:
apply plugin: 'com.android.application'
android {
...
flavorDimensions "myFlavorDimension"
productFlavors {
VariantName1 {
...
}
VariantName2 {
...
}
VariantName3 {
...
}
}
...
}
dependencies {
...
}
You can find these gradle task names either in Android Studio in the Gradle Tab (right side of GUI) under you moduleName->Tasks->install
Or you can find them in the terminal with:
./gradlew tasks | grep install
I'm sure there is some Regex that could grab only the ones of interest programmatically as well, but I'm not a regex buff. If you want to leave a comment with something that would work, I'd be happy to edit and add later.