I'm trying to use a fragment autocomplete UI from ---> https://docs.mapbox.com/android/plugins/overview/places/
but the IDE says that it can't resolve the symbol CarmenFeature and I don't know how to import that class or solve this exception
I've tried :
to import ---> import com.mapbox.api.v4.models.CarmenFeature;
but I think that the API folder does not exist
sync with gradle
invalidate cache and restart
rebuild project
clean project
autocompleteFragment = (SupportPlaceAutocompleteFragment) getSupportFragmentManager().findFragmentByTag(TAG);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
#Override
public void onPlaceSelected( CarmenFeature carmenFeature) {
}
#Override
public void onError(Status status) {
}
});
Well the problem is that the class cannot be imported and loaded. You need to configure inside the build.gradle in the root of your project :
allprojects {
repositories {
...
...
maven
{
url 'https://mapbox.bintray.com/mapbox'
}
}
}
and inside your /app/build.gradle :
dependencies {
...
...
// MAPBOX DEPENDENCIES
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:6.5.0#aar')
{
transitive=true
}
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.20.0'
implementation ('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.20.0')
{
transitive = true
}
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.android.support:design:27.0.2'
}
this is enough to use the CarmenFeature class.
Related
I just write a class which extends Transform class like this:
package com.example.plugin;
import org.gradle.internal.impldep.org.apache.commons.io.FileUtils;
import ...;
public class MyTransform extends Transform{
...
#Override
public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
Collection<TransformInput> inputs = transformInvocation.getInputs();
TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
inputs.forEach(transformInput -> {
transformInput.getJarInputs().forEach(jarInput -> {
File dest = outputProvider.getContentLocation(jarInput.getName(), jarInput.getContentTypes(), jarInput.getScopes(), Format.JAR);
try {
// System.out.println(jarInput.getName());
FileUtils.copyFile(jarInput.getFile(), dest);
} catch (IOException e) {
e.printStackTrace();
}
});
transformInput.getDirectoryInputs().forEach(directoryInput -> {
File dest = outputProvider.getContentLocation(directoryInput.getName(), directoryInput.getContentTypes(), directoryInput.getScopes(), Format.DIRECTORY);
try {
// System.out.println(directoryInput.getName());
FileUtils.copyDirectoryToDirectory(directoryInput.getFile(), dest);
} catch (IOException e) {
e.printStackTrace();
}
});
});
}
}
However, when I use it on other gradle application, it got error with gradle build:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMr_Spade is coming.ForDebug'.
> org/gradle/internal/impldep/org/apache/commons/io/FileUtils
It seems that the class FileUtils has some problems, but I just don't know what's wrong.
Here is the build.gradle of plugin:
plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
id 'java-gradle-plugin'
id 'maven-publish'
}
dependencies {
implementation 'org.testng:testng:7.4.0'
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
implementation 'com.android.tools.build:gradle:7.1.3'
implementation "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2"
// implementation 'org.ow2.asm:asm:9.2'
// implementation 'org.ow2.asm:asm-tree:9.2'
implementation 'org.apache.commons:commons-io:1.3.2'
}
gradlePlugin {
// Define the plugin
plugins {
greeting {
id = 'com.example.plugin.greeting'
implementationClass = 'com.example.plugin.Plugin_project_namePlugin'
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'aaa.bbb'
artifactId = 'ccc.ddd'
version = '1.0'
from components.java
}
}
repositories {
maven {
// change to point to your repo, e.g. http://my.org/repo
url = layout.buildDirectory.dir('../../repo')
}
}
}
...
build.gradle of application:
plugins {
id 'com.android.application'
id 'com.example.plugin.greeting'
}
...
dependencies {
// implementation gradleApi() //gradle sdk
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
// implementation 'org.apache.commons:commons-io:1.3.2'
...
}
By the way, since my plugin folder and app folder are in the same folder, so i will use command like "build"(for plugin)->"publish"(for plugin)->"build"(for app), and the fact is the first two step is success, but the last step is failed. Just like that the plugin itself do not have problem but occurs some problem when it work on the app :(
This is my first javafx and gradle application. First I created a gradle project in IntelliJ and then I added JavaFX dependencies referring this tutorial. My gradle file looks like this:
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
plugins {
id 'application'
}
group 'com.skb'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
def javaFXPlatform = getJavaFXPlatform()
def javaFXVersion = "15.0.1"
dependencies {
// you need a dependency for each of the JavaFX modules you're going to use
implementation "org.openjfx:javafx-base:${javaFXVersion}:${javaFXPlatform}"
implementation "org.openjfx:javafx-controls:${javaFXVersion}:${javaFXPlatform}"
implementation "org.openjfx:javafx-graphics:${javaFXVersion}:${javaFXPlatform}"
}
application {
//Java Module System module name
mainModule.set('com.skb')
//Your JavaFX application class
mainClass.set('com.skb.EditorApp')
}
java {
// this enables Java Modularity in Gradle (version 6.7 and above)
modularity.inferModulePath.set(true)
}
// Based on this StackOverflow answer: https://stackoverflow.com/a/65209664/653519
private static String getJavaFXPlatform() {
def currentOS = DefaultNativePlatform.currentOperatingSystem
if (currentOS.isWindows()) {
return 'win'
} else if (currentOS.isLinux()) {
return 'linux'
} else if (currentOS.isMacOsX()) {
return 'mac'
}
return null
}
My module_info.java lloks like this:
module com.skb {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
requires java.base;
//requires org.fxmisc.richtext;
//requires org.json;
opens com.skb;
}
EditorApp class contains just some biolerplate code:
package com.skb;
import javafx.application.Application;
import javafx.stage.Stage;
public class EditorApp extends Application {
#Override
public void start(Stage primaryStage) {
System.out.println("Running...");
}
public static void main(String[] args) {
launch(args);
}
}
Project structure is like this:
I am using IntelliJ 2021.1 Community Edition.
Please help me out. I have already searched a lot on this error, and got nothing that solved the error.
My plugin worked in Gradle v4.7, but is now crashing v5.2.1. I know that's a HUGE version jump.
I wrote a custom Gradle java plugin, and this the plugin implementation class. I put a breakpoint in the task.setProject(project) call, but it never gets there.
package com.zift.utilities;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
public class ZiftVersionPlugin implements Plugin<Project> {
public void apply(Project project) {
project.getTasks().create("manageVersion", ZiftVersion.class, (task) -> {
// Added breakpoint here, but it's never reached!
task.setProject(project);
});
}
}
Edit: (added simplified plugin code below)
Here's the simplified class that implements the manageVersion task. All the import statements will probably be unnecessary with this code.
package com.zift.utilities;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.options.Option;
import org.gradle.api.Project;
public class ZiftVersion extends DefaultTask {
#Input private Project project;
private String projectDir=null;
private String propFileFullPath=null;
private String sourceBranch=null;
private String destinationBranch="staging";
String getPropFile() { return propFileFullPath; }
void setPropFile(String fn) { this.propFileFullPath = fn; }
public Project getProject() { return project; }
public void setProject(Project project) {
this.project = project;
this.projectDir = this.project.getRootDir().toString();
}
// The void set*() functions have to immediately follow their corresponding
// #Option() so they can take arguments in the command line, e.g.,
// $ ./gradlew manageVersion \
// --srcBranch=bugfix/devops-507-semver --dstBranch=master
#Option(option = "srcBranch", description = "Source branch of the pull request")
public void setSrcBranch(String s) { this.sourceBranch = s; }
public String getSrcBranch() { return sourceBranch; }
#Option(option = "dstBranch", description = "Destination branch of the pull request")
public void setDstBranch(String d) { this.destinationBranch = d; }
public String getDstBranch() { return destinationBranch; }
#TaskAction
void manageProjectVersion() {
System.out.println("Hello world!");
}
}
Here's my project's build.gradle file to build the plugin
plugins {
id 'idea'
id 'java'
id 'maven'
id 'maven-publish'
id 'java-gradle-plugin'
}
group=project.groupId
version = '666.666.666'
dependencies {
compile gradleApi()
}
jar {
manifest {
attributes 'artifactId': 'zift-version-plugin',
'groupId': 'com.zift.utilities',
'version': project.version
}
baseName artifactId
doLast {
println "artifactId: $project.artifactId\ngroupId: $project.groupId\nversion: $version"
}
}
gradlePlugin {
plugins {
simplePlugin {
id = 'com.zift.utilities.zift-version-plugin'
implementationClass = 'com.zift.utilities.ZiftVersionPlugin'
}
}
}
Here's how I use it, from another Gradle project that uses the plugin
$ ./gradlew manageVersion --srcBranch=feature/devops-507-semver-support --dstBranch=master
> Task :manageVersion
Hello world!
Here's the exception, which looks like it occurred during the create() function call.
Caused by org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException: Could not create task ':manageVersion'
Caused by java.lang.NullPointerException: (No message provided)
at org.gradle.api.internal.tasks.TaskPropertyUtils.visitProperties(TaskPropertyUtils.java:38)
at org.gradle.api.internal.project.taskfactory.PropertyAssociationTaskFactory.create(PropertyAssociationTaskFactory.java:49)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.create(AnnotationProcessingTaskFactory.java:46)
...
at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:359)
at com.zift.utilities.ZiftVersionPlugin.apply(ZiftVersionPlugin.java:8)
Any clues?
Idiocy is the cause, my idiocy particularly.
I compiled my plugin with Gradle wrapper from v4.x, so when a project built with v5.x or above uses it, the plugin crashes.
Solution is to upgrade my plugin's wrapper to Gradle v6.0, build and publish a new version, and have projects use the new version. No more crashes.
I am trying to add a native prebuilt shared library to my project in Android Studio. I am using the gradle-experimental:0.6.0-alpha5. However, whenever I try to add the prebuilt shared library to my application model, I get the following error:
Error:Cause:
org.gradle.api.internal.PolymorphicDomainObjectContainerConfigureDelegate
The library is added into the application model how it is described by the Google Gradle Experimental Guide:
repositories {
prebuilt(PrebuiltLibraries) {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("/path_to_libs/${targetPlatform.getName()}/shared_lib.so")
}
}
}
android.sources {
main {
jniLibs {
dependencies {
library "shared_lib"
}
}
}
}
The crucial line is library "shared_lib". There is no error if I uncomment this line.
Since this is not working, I have also tried to use the guide from ph0b.com. They are using a different syntax for adding native shared libraries (I just left out the headers since I do not have a single directory including all headers):
repositories {
libs(PrebuiltLibraries) {
shared_lib {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("/path_to_libs/${targetPlatform.getName()}/shared_lib.so")
}
}
}
}
android.sources {
main {
jni {
dependencies {
library "shared_lib" linkage "shared"
}
}
}
}
Nevertheless, this does not work as well. Android Studio does not copy my shared_lib to the apk file. Hence, I always get the following error:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader [...] couldn't find "shared_lib.so"
Can anyone tell me how I can include native prebuild library into my project? I am using buildToolsVersion = '22.0.1' and compileSdkVersion = 22 as build parameters.
This one worked for me (0.6.0-beta6).
repositories {
prebuilt(PrebuiltLibraries) {
YourLib {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("src/main/libs/armeabi-v7a/libYourLib.so")
}
}
}
}
android.sources {
main {
jniLibs {
dependencies {
library "YourLib"
}
}
}
}
Looks like they just forgot to mention the "YourLib {}" part around "binaries.withType".
I try to write a gradle task with kotlin, this is my code.:
GreetingTask.kt
class GreetingTask : DefaultTask() {
#TaskAction
fun greet() {
println("greet!")
}
}
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.613"
}
}
apply plugin: "kotlin"
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:0.12.613"
compile gradleApi()
}
GreetingTaskTest
class GreetingTaskTest {
#Test
public fun canAddTaskToProject() {
val project = ProjectBuilder.builder().build()
val task = project.task(hashMapOf("type" to javaClass<GreetingTask>()), "greeting")
assertTrue(task is GreetingTask)
}
}
When running the test now it results in a:
java.lang.VerifyError at GreetingTaskTest.kt:20
// reason -> Cannot inherit from final class
Which is this line:
val task = project.task(hashMapOf("type" to javaClass<GreetingTask>()), "greeting")
What i would like to know is:
Where does this issue come from and how do i fix it?
Classes in Kotlin are final by default, compared to open in java.
Declare the class GreetingTask as "open" and this error message is gone.
open class GreetingTask : DefaultTask() {
...
}