homerours/cordova-music-controls-plugin

Build failed: Task :app:compileDebugJavaWithJavac FAILED

tbergeron opened this issue · 15 comments

I'm having issues building the app for Android. FYI: I use Ionic but it shouldn't matter since this is cordova/java-related.

I tried using cordova-android 6.3, 6.4, 7.1 & 8.0 but to no avail. I always get the same build errors. So I'm starting to wonder if there's something wrong with my config. I get this error both on Windows 10 & Mac OS. I have the same config / versions on both setup.

Here's the build logs:

BUILD FAILED in 2m 59s
> Task :app:compileDebugJavaWithJavac FAILED
24 actionable tasks: 24 executed
C:\Users\anon\Workshop\polycast-frontend\platforms\android\gradlew: Command failed with exit code 1 Error output:
Note: C:\Users\anon\Workshop\polycast-frontend\platforms\android\CordovaLib\src\org\apache\cordova\engine\SystemCookieManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\anon\Workshop\polycast-frontend\platforms\android\app\src\main\java\com\homerours\musiccontrols\MediaSessionCallback.java:54: error: method does not override or implement a method from a supertype
  @Override
  ^
C:\Users\anon\Workshop\polycast-frontend\platforms\android\app\src\main\java\com\homerours\musiccontrols\MediaSessionCallback.java:56: error: cannot find symbol
    super.onPlayFromMediaId(mediaId, extras);
         ^
  symbol: method onPlayFromMediaId(String,Bundle)
C:\Users\anon\Workshop\polycast-frontend\platforms\android\app\src\main\java\com\homerours\musiccontrols\MusicControls.java:72: error: cannot find symbol
                this.mediaSessionCompat.setMediaButtonReceiver(this.mediaButtonPendingIntent);
                                       ^
  symbol:   method setMediaButtonReceiver(PendingIntent)
  location: variable mediaSessionCompat of type MediaSessionCompat
C:\Users\anon\Workshop\polycast-frontend\platforms\android\app\src\main\java\com\homerours\musiccontrols\MusicControls.java:80: error: cannot find symbol
                this.mediaSessionCompat.setMediaButtonReceiver(null);
                                       ^
  symbol:   method setMediaButtonReceiver(<null>)
  location: variable mediaSessionCompat of type MediaSessionCompat
C:\Users\anon\Workshop\polycast-frontend\platforms\android\app\src\main\java\com\homerours\musiccontrols\MusicControls.java:103: error: no suitable constructor found for MediaSessionCompat(Context,String,<null>,PendingIntent)
                this.mediaSessionCompat = new MediaSessionCompat(context, "cordova-music-controls-media-session", null, this.mediaButtonPendingIntent);
                                          ^
    constructor MediaSessionCompat.MediaSessionCompat(Context,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor MediaSessionCompat.MediaSessionCompat(MediaSessionImpl) is not applicable
      (actual and formal argument lists differ in length)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

Here's my Windows 10 config:

cli packages: (C:\Users\anon\AppData\Roaming\npm\node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : 8.1.2 (cordova-lib@8.1.1)

local packages:

    @ionic/app-scripts : 3.1.0
    Cordova Platforms  : android 6.4.0 ios 4.5.5
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v8.11.1
    npm  : 5.6.0
    OS   : Windows 10

EDIT: Here's my config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.brainpad.polycast" version="0.0.41" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Polycast</name>
    <description>Get informed and entertained.</description>
    <author email="support@brainpad.org" href="https://brainpad.org/">Brainpad Consulting</author>
    <content src="index.html" />
    <access origin="*" />
    <access launch-external="yes" origin="ftp://*" />
    <access launch-external="yes" origin="http://*" />
    <access launch-external="yes" origin="https://*" />
    <allow-navigation href="http://ionic.local/*" />
    <allow-navigation href="http://192.168.1.106:8100" sessionid="e35752d5" />
    <allow-navigation href="http://192.168.1.135:8100" />
    <allow-navigation href="http://192.168.56.1:8100" />
    <allow-navigation href="http://192.168.1.112:8100" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
        <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
    </platform>
    <platform name="ios">
        <config-file mode="add" parent="ITSAppUsesNonExemptEncryption" target="*-Info.plist">
            <false />
        </config-file>
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <icon height="20" src="resources/ios/icon/icon-20.png" width="20" />
        <icon height="48" src="resources/ios/icon/icon-24@2x.png" width="48" />
        <icon height="55" src="resources/ios/icon/icon-27.5@2x.png" width="55" />
        <icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
        <icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80" />
        <icon height="120" src="resources/ios/icon/icon-40@3x.png" width="120" />
        <icon height="88" src="resources/ios/icon/icon-44@2x.png" width="88" />
        <icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
        <icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100" />
        <icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
        <icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120" />
        <icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180" />
        <icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
        <icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144" />
        <icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
        <icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152" />
        <icon height="167" src="resources/ios/icon/icon-83.5@2x.png" width="167" />
        <icon height="172" src="resources/ios/icon/icon-86@2x.png" width="172" />
        <icon height="196" src="resources/ios/icon/icon-98@2x.png" width="196" />
        <icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
        <icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
        <icon height="58" src="resources/ios/icon/icon-small@2x.png" width="58" />
        <icon height="87" src="resources/ios/icon/icon-small@3x.png" width="87" />
        <icon height="57" src="resources/ios/icon/icon.png" width="57" />
        <icon height="114" src="resources/ios/icon/icon@2x.png" width="114" />
        <splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
        <splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
        <splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
        <splash height="2436" src="resources/ios/splash/Default-2436h.png" width="1125" />
        <splash height="1242" src="resources/ios/splash/Default-Landscape-736h.png" width="2208" />
        <splash height="1125" src="resources/ios/splash/Default-Landscape-2436h.png" width="2436" />
        <splash height="2048" src="resources/ios/splash/Default-Landscape@~ipadpro.png" width="2732" />
        <splash height="1536" src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" />
        <splash height="768" src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" />
        <splash height="2048" src="resources/ios/splash/Default-Portrait@~ipadpro.png" width="2732" />
        <splash height="1536" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="2048" />
        <splash height="768" src="resources/ios/splash/Default-Portrait~ipad.png" width="1024" />
        <splash height="2732" src="resources/ios/splash/Default@2x~ipad~anyany.png" width="2732" />
        <splash height="2732" src="resources/ios/splash/Default@2x~ipad~comany.png" width="1278" />
        <splash height="640" src="resources/ios/splash/Default@2x~iphone.png" width="960" />
        <splash height="1334" src="resources/ios/splash/Default@2x~iphone~anyany.png" width="1334" />
        <splash height="1334" src="resources/ios/splash/Default@2x~iphone~comany.png" width="750" />
        <splash height="750" src="resources/ios/splash/Default@2x~iphone~comcom.png" width="1334" />
        <splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
        <splash height="2208" src="resources/ios/splash/Default@3x~iphone~anyany.png" width="2208" />
        <splash height="1242" src="resources/ios/splash/Default@3x~iphone~anycom.png" width="2208" />
        <splash height="2208" src="resources/ios/splash/Default@3x~iphone~comany.png" width="1242" />
        <splash height="320" src="resources/ios/splash/Default~iphone.png" width="480" />
    </platform>
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
    <plugin name="cordova-plugin-device" spec="^1.1.4" />
    <plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
    <plugin name="cordova-plugin-ionic-webview" spec="^1.2.1" />
    <plugin name="cordova-plugin-app-version" spec="^0.1.9" />
    <plugin name="cordova-plugin-nativestorage" spec="^2.3.2" />
    <plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
    <plugin name="cordova-plugin-android-support-v4" spec="^21.0.1" />
    <plugin name="cordova-plugin-music-controls" spec="https://github.com/homerours/cordova-music-controls-plugin.git" />
    <engine name="ios" spec="4.5.5" />
    <engine name="android" spec="6.4.0" />
</widget>

And my package.json:

{
  "name": "podcast-player",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "5.0.0",
    "@angular/compiler": "5.0.0",
    "@angular/compiler-cli": "5.0.0",
    "@angular/core": "5.0.0",
    "@angular/forms": "5.0.0",
    "@angular/http": "5.0.0",
    "@angular/platform-browser": "5.0.0",
    "@angular/platform-browser-dynamic": "5.0.0",
    "@ionic-native/app-version": "^4.20.0",
    "@ionic-native/core": "4.3.2",
    "@ionic-native/music-controls": "^4.20.0",
    "@ionic-native/native-storage": "^4.20.0",
    "@ionic-native/splash-screen": "4.3.2",
    "@ionic-native/status-bar": "4.3.2",
    "@ionic/storage": "2.1.3",
    "cordova-android": "6.4.0",
    "cordova-ios": "4.5.5",
    "cordova-plugin-android-support-v4": "^21.0.1",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-device": "^1.1.4",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^1.2.1",
    "cordova-plugin-music-controls": "git+https://github.com/homerours/cordova-music-controls-plugin.git",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.1",
    "feedparser": "^2.2.1",
    "ionic-angular": "3.9.2",
    "ionic-audio": "github:tbergeron/ionic-audio#3.0",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "3.0.0",
    "rxjs": "5.5.2",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.0",
    "typescript": "~2.6.2"
  },
  "description": "podcast-player: An Ionic project",
  "cordova": {
    "platforms": [
      "ios",
      "android"
    ],
    "plugins": {
      "ionic-plugin-keyboard": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-app-version": {},
      "cordova-plugin-nativestorage": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-android-support-v4": {},
      "cordova-plugin-music-controls": {}
    }
  }
}

Anyone sees anything wrong? Why am I getting these errors?

I used to have Android v4 build errors, then I installed cordova-plugin-android-support-v4 and they went away. Now I'm stuck on these build errors. Any ideas will be welcome! Thanks

Try adding also plugin "cordova-plugin-android-support-v4-jar" to the project

@NorthFred it's already there listed

<plugin name="cordova-plugin-android-support-v4" spec="^21.0.1" />

I had Android v4 errors prior to this, now it's only these build errors that I don't know about... Any idea?

@tbergeron: The plugin has a slightly different name: "cordova-plugin-android-support-v4-jar".
It's a subtle difference :) Please try with that one!

Oh I see! I will try! So basically I should replace the one I have with this one? Not keep both right? @NorthFred thanks for the help!

EDIT: After having updated ionic-audio, I now only have these errors: (seems to be gradle-related)

> cordova build android
⠸ Running command [09:35:20]  lint finished in 5.71 s 
✔ Running command - done!
ANDROID_HOME=/Users/tommybergeron/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Subproject Path: CordovaLib
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
	at build_3gv1pmjr3bbcvha52jof88waw.run(/Users/tommybergeron/Desktop/Workshop/polycast-frontend/platforms/android/build.gradle:141)
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
:preBuild UP-TO-DATE
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:checkDebugManifest UP-TO-DATE
:CordovaLib:processDebugManifest UP-TO-DATE
:preDebugBuild UP-TO-DATE
:CordovaLib:compileDebugAidl UP-TO-DATE
:compileDebugAidl UP-TO-DATE
:CordovaLib:packageDebugRenderscript NO-SOURCE
:compileDebugRenderscript UP-TO-DATE
:checkDebugManifest UP-TO-DATE
:generateDebugBuildConfig
:prepareLintJar UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:CordovaLib:compileDebugRenderscript UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE
:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources UP-TO-DATE
:mergeDebugResources
:createDebugCompatibleScreenManifests
:processDebugManifest
:splitsDiscoveryTaskDebug UP-TO-DATE
:CordovaLib:platformAttrExtractor UP-TO-DATE
:CordovaLib:processDebugResources UP-TO-DATE
:processDebugResources
:generateDebugSources
:CordovaLib:generateDebugBuildConfig UP-TO-DATE
:CordovaLib:prepareLintJar UP-TO-DATE
:CordovaLib:generateDebugSources UP-TO-DATE
:CordovaLib:javaPreCompileDebug UP-TO-DATE
:CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
:CordovaLib:processDebugJavaRes NO-SOURCE
:CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
:javaPreCompileDebug UP-TO-DATE
:compileDebugJavaWithJavac FAILED
27 actionable tasks: 6 executed, 21 up-to-date

@NorthFred THANKS! With both installed it works as expected! (if I remove any of them it stops working)

It worked for a few times and now I get the same error DAMN IT

I tried removing cordova-plugin-android-support-v4 to see if it would work without it. It did not. Tried putting it back in and since then I get the same errors as before... :( It worked a few times when I had just added cordova-plugin-android-support-v4-jar... Wonder what is wrong...

IMO after reading docs, I guess only one is needed.
The thing I wonder is why it worked and stopped. I read here ionic cordova plugin add cordova-plugin-android-support-v4-jar that I might need to update the .jar file of the plugin with the latest SDK version. But WHY did it worked? Damn this is weird. Hope I can figure it out quick hehe

Ok I got it:
I removed all the v4 plugins I had. Made sure everything was cleaned.. package-lock.json, node_modules, plugins, etc. Then I re-installed the -jar one and it started working again!

@tbergeron after following your advice and adding android-support-v4-jar I always get the :app:transformClassesWithMultidexlistForDebug error on build
that is also discussed here #88 (comment)

I tried the https://github.com/jwall149/cordova-multidex plugin aswell as the
https://github.com/dpa99c/cordova-android-support-gradle-release

Have you done anything different as it seems to work for you?

Just for info: I resolved the problem by not using any of the cordova support libs at all, this has caused the build problems. I opened the project in Android Studio and added the support library via the GUI. I know this is not ideal because I'll have to redo this step when I readd the platform but at least it works now :)

@tobika How did you add the support library with the GUI? Not familiar with Android Studio and google is just giving answers from really old versions that aren't applicable...

@rastographics once you are in android studio, right click on app then Open Module Settings then Dependencies

Screenshot from 2019-04-16 15-02-36

Thank you, this worked for me when no other solutions did.

Thanks you @tobika , it works!!!

I've fixed it without Android Studio workaround, you need to add the code to project.properties file, worked for me on Ionic 3 (sdk28):
cordova.system.library.2=com.android.support:support-annotations:28.+
cordova.system.library.3=com.android.support:support-media-compat:28.+

#145