Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find source java class while developing plugin for cordova (Android)

I'm developing an plugin to cordova which uses an brazilian payment api called pagseguro. But that's not the point.

When I add my cordova plugin to my project and run "cordova run android", I receive this error and I don't know how to proceed:

Execution failed for task ':app:compileDebugJavaWithJavac'.

Unable to find source java class: '/home/marcelo/Documents/Delicia-e-Foco/app/platforms/android/app/src/main/java/main/java/com/pagseguroCordova/PagseguroCordova.java' because it does not belong to any of the source dirs: '[/home/marcelo/Documents/Delicia-e-Foco/app/platforms/android/app/src/main/java, /home/marcelo/Documents/Delicia-e-Foco/app/platforms/android/app/src/debug/java, /home/marcelo/Documents/Delicia-e-Foco/app/platforms/android/app/build/generated/source/r/debug, /home/marcelo/Documents/Delicia-e-Foco/app/platforms/android/app/build/generated/source/buildConfig/debug, /home/marcelo/Documents/Delicia-e-Foco/app/platforms/android/app/build/generated/source/aidl/debug, /home/marcelo/Documents/Delicia-e-Foco/app/platforms/android/app/build/generated/source/rs/debug]'

Already tried to modify my plugin.xml. this is the plugin.xml right now:

<?xml version="1.0" encoding="UTF-8"?>
    <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-pagseguro"
version="1.0.0">

<js-module src="./www/plugin.js" name="plugin">
    emphasized text<clobbers target="PagseguroCordova" />
</js-module>

<!-- android -->
<platform name="android">
    <config-file target="res/xml/config.xml" parent="/*">
        <feature name="pagseguroCordova" >
            <param name="android-package" value="com.example.pagseguroCordova"/>
        </feature>
    </config-file>

    <framework src="build.gradle" custom="true" type="gradleReference" />
    <framework src='br.uol.pagseguro.client:btserial:1.1.0' />
    <framework src='br.uol.pagseguro.client:plugpag:1.1.0' />
    <source-file src="src/android/PagseguroCordova.java" target-dir="src/main/java/com/pagseguroCordova/" />
</platform>

I'm using gradle to import dependecies, this is my build.gradle file:

repositories {
    jcenter()
        maven {
            url 'https://github.com/pagseguromaster/plugpag/raw/master/android'
    }
}

dependencies {
    compile 'br.uol.pagseguro.client:btserial:1.1.0'
    compile 'br.uol.pagseguro.client:plugpag:1.1.0'
}

Someone knows what is causing this error? Thanks for the attention.

like image 620
user3119509 Avatar asked Apr 16 '18 20:04

user3119509


3 Answers

A 'Clean Project' from the Android Studio 'Build' dropdown fixed this for me.

like image 79
Jochem Avatar answered Nov 13 '22 17:11

Jochem


Deleting the .idea and .gradle folders worked for me.

Next time you launch open the project folder in Android Studio it should recreate them.

However it then gives me the Android Studio: "Please select Android SDK" dialog.

Fix for me is: File -> Project Structure -> (modules)App -> BuildToolsVersion -> ... and then (bizarrely) click to open the pulldown and click on the exact same item that was already selected.

And then rebuild.

Sort it out, Google!

(Android Studio 3.1.2)

like image 7
P i Avatar answered Nov 13 '22 16:11

P i


I am not using any special IDE (yes I live under a rock)

cordova clean

works for me

like image 4
Arindam Avatar answered Nov 13 '22 16:11

Arindam