Ionic build android not copying latest files to platforms/android (or anywhere else)

When I run ionic build android from my project’s directory, it copies a version of my app from like 6 weeks ago in the platforms/android folder. Here are steps I’ve tried to rectify this issue:

  1. I’ve deleted some of the files that were used in this old build, including deleting them from /platforms/android and both myapp/src and myapp/www, and somehow the ionic build android command recovers these files from god knows where and copies them into the platforms/android folder.
  2. I’ve tried updating my version number in my config.xml file.
  3. I’ve tried deleting the APK and various other files from /build/android as well as deleting the entire platforms/android folder and the entire platforms folder.
  4. I’ve uninstalled and reinstalled both ionic and cordova (npm install/uninstall -g ionic/cordova)
  5. I tried creating a new ionic app with ionic start and then after cding into the new directory for my new project and running the same two commands, I got the old version of my other app. Messed up!
  6. I’ve tried removing and then adding back cordova android with both the commands ionic cordova platform rm/add android and cordova platform rm/add android.

I’m at my wit’s end here. Here’s ionic info:

cli packages: (C:\Users\max\Documents\omsLibrary\node_modules)

    @ionic/cli-utils  : 1.13.1
    ionic (Ionic CLI) : 3.13.1

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 1.3.7
    Cordova Platforms  : android
    Ionic Framework    : ionic-angular 3.7.1

System:

    Android SDK Tools : 26.1.1
    Node              : v6.9.2
    npm               : 5.4.2
    OS                : Windows 10

Misc:

    backend : pro

The one weird thing I’m seeing is

C:\Users\max\Documents\omsLibrary>ionic cordova platforms add android
> cordova platform add android --save
× Running command - failed!
[WARN] Platform already added. Saving platforms to config.xml.
> cordova platform save
√ Running command - done!
> ionic cordova resources android --force
√ Collecting resource configuration and source images - done!

? Platform android not detected. Would you like to install it? Yes
> cordova platform add android --save
× Running command - failed!
[WARN] Platform already added. Saving platforms to config.xml.
> cordova platform save
√ Running command - done!
[ERROR] No platforms detected. Please run: ionic cordova platform add

If I run it again, the loop starts over, so I look in the platforms/android folder, and it looks like it installed, so I run ionic cordova build android and everything seems fine except for this note at the top:

C:\Users\max\Documents\omsLibrary>ionic cordova build android
> cordova platform add android --save
× Running command - failed!
[WARN] Platform already added. Saving platforms to config.xml.
> cordova platform save
√ Running command - done!

Once again it’s trying to add the platform. Once again, it’s realizing it has the platform. Sigh. I wouldn’t care about this issue if the build still worked, but of course, there’s that big problem of the compiled app not being copied into the build/android folder. When I copy over the contents of myapp/www into platforms/android/assets/www/build, and then open the android directory in Android Studio, it does recompile into my latest app, but I don’t want to have to go through all of that every time I want to test something on Android!

Please, any help is appreciated. My best guess is this has something to do with some sort of busted caching in cordova or ionic, but I can’t find any information on that.

Try updating your app-scripts, the current version is 3.0, and I’m unsure if 1.3.7 will work with any of the newer versions of ionic-angular.

Also, I would recommend removing all platforms and using the ionic CLI to add and remove platforms in the future. E.g., cordofva platform add android should actually be ionic cordova platform add android. Same with the platform rm commands too.

He is using the correct commands, what you are seeing there is the output of Ionic CLI that is calling these commands.

Do you use Ionic Deploy?
Do you have the Ionic Pro plugin installed?
Which plugins do you have installed?

Can you check out the project in another folder and try there?
Can you build a new project created with ionic start without this strange loop?

Whoops good catch! In that case I would rm -rf platforms and plugins. Then readd the platform.

Hi all, thank you so much for all the help. I finally figured this one out. Apparently, when I was first starting the project and I didn’t know what I was doing (not that I really know what I’m doing now!), I copied the contents of my project folder (max/documents/myapp) into its parent folder (max/documents) because I was making some change that I was worried would break things. I completely forgot I had done this. When I deleted all those files from my documents folder, it worked!

So what I think was happening was the different mechanisms in the build process used different logic to determine where the project and platforms folders are.The add platform command was adding the platform to its right location, but the find platform command was looking I suppose in /max rather than /max/documents for the platforms folder and failing to find it. Then the copy project files to build folder command was finding the correct destination but looking in /documents rather than /documents/myapp to find the files to be copied over to /max/documents/platforms/android and finding the code from my ancient version of the app.

Thanks again for taking the time out to give me tips. I appreciate it.