Spark Dev: app code was invalid

Hi damccull,

I think there is no fix still but the alternative is to create a empty folder and copy your .ino file into that folder. This should solve the problem. :smiley:

And that apparently means only one .ino file per folder.

I was getting this unusual “app code was invalid” message when I had two different .ino files in the same Programs folder.
Moving one to a Programs2 folder solved this.

But it is a lousy way to have to do development.

No choice hahaha. But this method works so I am fine with it :smile:

Hi, new to this. I am getting the same error. I developed a program in the WEB IDE, so I know it compiles, loads and runs. Copied and pasted that program to the Spark Dev on my Mac. Saved it in an empty folder with the .ino extension. It will not compile in Spark Dev. I get the App code was invalid error. Also tried saving the same code to another file with the .cpp extension, also in an empty folder by another name. Also tried quit Spark Dev, restart, open, and still get the error.

Is there some black magic to the folder layout? I’ve got a folder names SPARK in my Documents folder. Inside the SPARK folder are the two folders mentioned above, named TempLight1 and TempLight2. In those folders are the .ini, in 1 and the .cpp in 2.

I get the error and can make no progress. This has to be something simple. Can anyone suggest a solution? And, it probably should not be so hard to save a project in Spark Dev… hint hint.

Have you checked all the possible reasons pointed out in this thread - and the others dealing with “App code was invalid”?
Obviously you already avoided some of the most common traps.

Would you mind sharing your code and meanwhile try a very minimalistic sketch in Spark Dev?
Could you also post a screenshot of your Spark Dev window?

1 Like

Thanks for trying to help. Forgive me for being blind, but I can’t see any suggestions in this post other than being certain to have only one file in the project folder. I’ve supplied my names for the file and the folder structure in the other post, which is being killed by moderator (sorry to double up.) It is Documents > Spark > TempLight1 > TempLight1.ino and then the same structure for another >TempLight2 > TempLight.cpp

ScruffR, could you summarize the “other reasons” for this error? I just don’t see them.

As for the other threads that deal with this problem, I’ve searched and this is the only thread I could find. Could you tell me how to locate the other threads please.

This is obviously a common problem and it is insidious because the solution is not in the documentation, the error message provides no information for problem resolution and it appears to be the result of any of a number of idiosyncrasies. Putting possible solution in one post would be very helpful. If I could be pointed to the disparate solutions, I’d compose and post the summary.

1 Like

I’m not trying to kill anything, rather keeping the forum clean since you’ve got the exact same issues as in this post. Therefore I feel it’s better to keep it together.

For the Spark Dev it’s important that you keep the files in a directory limited to those required for your program. That would be the main .ino file, and perhaps the required includes.
Also, note that you can’t (yet) add libraries like you do in the Web IDE. If you copy code from the Web IDE containing such #includes it’s not going to work. In order to get those working properly, follow these steps.
Nested directories are also known to cause problems. Open the main directory you’re working in, and not one two stories up.

Like @ScruffR mentioned, could you try compiling a very simple program, something like the blink a LED? This will rule out issues with your code, since that should work. Paste the code below into the Spark Dev and save as... a new file in a new directory. Then try compiling it. It should look something like this:

The code:

int led = D0;  // You'll need to wire an LED to this one to see it blink.
int led2 = D7; // This one is the built-in tiny one to the right of the USB jack

// This routine runs only once upon reset
void setup() {
  // Initialize D0 + D7 pin as output
  // It's important you do this here, inside the setup() function rather than outside it or in the loop function.
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
}

// This routine gets called repeatedly, like once every 5-15 milliseconds.
// Spark firmware interleaves background CPU activity associated with WiFi + Cloud activity with your code. 
// Make sure none of your code delays or blocks for too long (like more than 5 seconds), or weird things can happen.
void loop() {
  digitalWrite(led, HIGH);   // Turn ON the LED pins
  digitalWrite(led2, HIGH);
  delay(1000);               // Wait for 1000mS = 1 second
  digitalWrite(led, LOW);    // Turn OFF the LED pins
  digitalWrite(led2, LOW); 
  delay(1000);               // Wait for 1 second in off mode
}

Also, could you please share your code? Perhaps there’s something in there that’s causing problems.

Let us know how it worked out for you!

2 Likes

To list just a few of them (not all of them revolve around Spark Dev, but might give some clues - and there might be duplicate suggestions too)




Please share your code and provide some screenshot (of the complete Spark Dev window), since this might give us some clue about your setup and problem.

1 Like

Thanks for all the direction and the examples. I found the problem and it was nothing so elegant as those you’ve contributed this morning. It was simply that my file name had a space in it. “Temp Light.ino”. That space was causing the error. Funny that it would save and load with the space in it, but would not compile. And the error message doesn’t provide any help.

So here is one more item to add to the list of potential sources of App code was invalid. Don’t have a space in your file name.

BTW, I found the problem because I did cut the program down to a skeleton and saved under a different file name and folder, without putting in the space. So, it was that suggestion that got the ball rolling the right way. Thanks.

Glad you’ve got it working and we were able to help :smile:

Small tip for the future: NEVER, EVER, FOR ANY REASON, save a file with blank spaces. Anything programming related will be problematic if you do. Rather, use underscores if you must, or CamelCase. It’s just not worth the hassle of dealing with blanks.

That was one of the reasons I asked for a screenshot.
There might be a lot of possible causes to such a problem, that we (perviously burnt users) might see in an instant, but are tedious to find for you and for us to ask through all of them over and over again.
Not that we mind, but why not the easy way :wink:


As a clarification for why it saves without error but doesn’t build.
Spark Dev is mainly an editor and can deal with all sorts of file names, but for building it will just take your filename and supply it as a parameter to another program - e.g. gcc or Spark CLI or … doesn’t matter - and this might (definetly is) not as clever and sees the blanked name as two seperate parameters.
A way around this would be if Spark Dev wrapped the file name in quotation marks, but it doesn’t :weary:

2 Likes

Those are good suggestions. Next time I want to ask for help I will post a screenshot and the code along with the request. Thanks!

2 Likes

I’m now having this same problem. I had an app with multiple C++ files that compiled and ran correctly on Friday. Over the weekend, I added another .cpp and .h file. After cleaning up some compiler errors, it now gives the dreaded “App code was invalid”.

Here’s the Spark-Dev window:

How do I troubleshoot this?
And a possibly related question - how can I tell when I run out of code/ram space?

Thanks,
Ray

Have you not got an INO file in your project?

Maybe put the main part (setup() and loop()) in an INO and test again.

Another thing to watch is, that Spark Dev doesn’t auto-save before you build.
I noticed the blue icon on the TT_proto.cpp tab. If you change your code but don’t save manually, you’ll compile the old (previously saved) code and your changes will not come into effect.

There was no ino file before, and it compiled and ran as expected. But I tested your suggestion by renaming TT_proto.cpp to TT_proto.ino and got the same results.

Thanks for the tip on saving the file - I’m using a local code editor and rarely use the Dev editor.

Thanks,
Ray

Hi @rayz

Normally this message is due to a hidden file (like with .name) and Spark Dev doesn’t like that.

So I would look for any extra files in that directory. If that doesn’t do it, I would try copying the files from the current directory into a new clean directory and try that.

@ ScuffR & @bko,
Thanks for taking time to reply. There are no other files, but I followed your suggestion and:

  1. shut Dev down
  2. copied those 12 files to a new directory
  3. started Dev, opened the new directory, and compiled.

No joy; same result. This is really frustrating. If I can’t get some insight into the cause, I’ll have to go back to the 10 files I had last week and go incrementally until it fails. That sucks - these are not simple “blink an LED” functions.

Thanks,
Ray

Ahhhhhhh (pulling hair out). I copied the code from screens.cpp into TT_proto.cpp, and screens.h into TT_proto.h, then deleted the ‘screens’ files and it compiles and runs!

When I put the screens files back into the project directory and add some code to both, it reverts to the “App code was invalid” error.

So it seems that there is a 10 file limit in Dev??? Can anyone confirm or refute this?

Thanks,
Ray

2 Likes

I haven’t run into this trouble yet, but I guess the guy to ping for this might be @suda

Hey @rayz, sorry to hear about that. Have you tried compiling your project using CLI?