How to use @UsesServices Annotation?

i am getting a big error.

here is my code

@UsesServices(services = {@ServiceElement(name = ".Myservice", permission = "android.permission.WRITE_EXTERNAL_STORAGE" , intentFilters = {@IntentFilterElement(actionElements = {@ActionElement(name = "android.app.Service")})})})

my error log

error: InvocationTargetException when gathering service attributes and subelements for component RootChecker

kindly take a look here , sur @hammerhai

have you imported this :
import java.lang.reflect.InvocationTargetException;

1 Like

i already import these

 import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

This post was flagged by the community and is temporarily hidden.

i need your help :cry:

here is my error log

 @ServiceElement(name = ".RootChecker" ,intentFilters = {
    [javac]    ^
    [javac]   symbol: class ServiceElement
    [javac] error: InvocationTargetException when gathering service attributes and subelements for component TouchViewManager
    [javac]
    [javac]
    [javac] An annotation processor threw an uncaught exception.
    [javac] Consult the following stack trace for details.
    [javac] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    [javac]     at com.google.appinventor.components.scripts.ComponentProcessor.processComponent(ComponentProcessor.java:1310)
    [javac]     at com.google.appinventor.components.scripts.ComponentProcessor.process(ComponentProcessor.java:1070)
    [javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
    [javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
    [javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
    [javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
    [javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
    [javac]     at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
    [javac]     at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
    [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:523)
    [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:381)
    [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:370)
    [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:361)
    [javac]     at com.sun.tools.javac.Main.compile(Main.java:56)
    [javac]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [javac]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:498)
    [javac]     at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:58)
    [javac]     at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1395)
    [javac]     at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1121)
    [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    [javac]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:498)
    [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac]     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    [javac]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:498)
    [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac]     at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:402)
    [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    [javac]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:498)
    [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac]     at org.apache.tools.ant.Target.execute(Target.java:435)
    [javac]     at org.apache.tools.ant.Target.performTasks(Target.java:456)
    [javac]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
    [javac]     at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    [javac]     at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    [javac]     at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
    [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    [javac]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:498)
    [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac]     at org.apache.tools.ant.Target.execute(Target.java:435)
    [javac]     at org.apache.tools.ant.Target.performTasks(Target.java:456)
    [javac]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
    [javac]     at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
    [javac]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [javac]     at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    [javac]     at org.apache.tools.ant.Main.runBuild(Main.java:857)
    [javac]     at org.apache.tools.ant.Main.startAnt(Main.java:236)
    [javac]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
    [javac]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)
    [javac] Caused by: java.lang.reflect.InvocationTargetException
    [javac]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [javac]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:498)
    [javac]     at com.google.appinventor.components.scripts.ComponentProcessor.elementAttributesToString(ComponentProcessor.java:1645)
    [javac]     at com.google.appinventor.components.scripts.ComponentProcessor.serviceElementToString(ComponentProcessor.java:1507)
    [javac]     at com.google.appinventor.components.scripts.ComponentProcessor.processComponent(ComponentProcessor.java:1301)
    [javac]     ... 62 more
    [javac] Caused by: java.lang.annotation.IncompleteAnnotationException: com.google.appinventor.components.annotations.androidmanifest.ServiceElement missing element name
    [javac]     at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:81)
    [javac]     at com.sun.proxy.$Proxy21.name(Unknown Source)
    [javac]     ... 69 more

BUILD FAILED
C:\Users\dhana\appinventor-sources-master\appinventor\build.xml:46: The following error occurred while executing this line:
C:\Users\dhana\appinventor-sources-master\appinventor\components\build.xml:217: The following error occurred while executing this line:
C:\Users\dhana\appinventor-sources-master\appinventor\build-common.xml:125: Compile failed; see the compiler error output for details.

Total time: 30 seconds

This File Will Help You A Lot

1 Like

Please do not mention people all in one post otherwise they will not help you.

...

import com.google.appinventor.components.annotations.UsesServices;
import com.google.appinventor.components.annotations.androidmanifest.ActionElement;
import com.google.appinventor.components.annotations.androidmanifest.IntentFilterElement;
import com.google.appinventor.components.annotations.androidmanifest.ServiceElement;

@UsesServices(services = {
  @ServiceElement(
    name = "{packageName}.MyService",
    permission = "android.permission.WRITE_EXTERNAL_STORAGE",
    intentFilters = {
      @IntentFilterElement(
        actionElements = {
          @ActionElement(name = "android.app.Service")
        }
      )
    }
  )
})

Final solution

Import missing classes directly.

import com.google.appinventor.components.annotations.UsesServices;
import com.google.appinventor.components.annotations.androidmanifest.ActionElement;
import com.google.appinventor.components.annotations.androidmanifest.IntentFilterElement;
import com.google.appinventor.components.annotations.androidmanifest.ServiceElement;

Don’t forget to replace {packageName} with your extensions package name.

1 Like

@hammerhai Can you please give me a very simple code of extension which uses Services?
I am not understanding how to work with Services.

1 Like

Sure.

2 Likes

it looks like Kodular stil did not implement the new annotations…
see also

therefore that will only work in App Inventor currently until Kodular update their system…

Taifun

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.