Cannot build APK or run project on android device

I used the old sdk manager that works with JME, enabled android deployment, and turned off compile on save. No .APK is generated in the dist folder, and when I try to run using the “Android Device” configuration, i get this message:

Target "run-android" does not exist in the project "Crushed". 
BUILD FAILED (total time: 0 seconds)

My guess is I need to add a new target to the build file, but I have no idea what to put there.

I don’t think this matters, but I’m targeting Android 7.0(API 24 i think)

Did you try this boilerplate? It may be still working: JMonkeyEngine Android Template

Error window using bootmonkey: Project folder must not be empty.
Any ideas?

Also, would I have to create a new project with thisand copy my src and assets over?

I was able to create a JME Android app recently. Best advice I have is to use Android studio and use the JME Android Harness for the MainActivity.

There wasn’t much special in the JME version of the game other than simple controls.

Process:

  1. Make JME Game

Source is above.

  1. Make New Android Project
  2. Reference compiled Game.jar and all libraries you used
  3. Edit Manifest and MainActivity

My Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bigbawb.maniacmaze">

    <application
        android:versionCode="1"
        android:versionName="1.0" >
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        >

        <activity android:label="@string/app_name" android:launchMode="singleTask" android:name="MainActivity" android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

    </application>>

</manifest>

My Main Activity:

package com.bigbawb.apps.myapplication;

/**
 * Created by Bob on 6/29/2018.
 */

import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.jme3.app.AndroidHarness;

import java.util.logging.Level;
import java.util.logging.LogManager;

import mygame.AndroidManager;
import mygame.GameManager;

public class MainActivity extends AndroidHarness {

    /*
     * Note that you can ignore the errors displayed in this file,
     * the android project will build regardless.
     * Install the 'Android' plugin under Tools->Plugins->Available Plugins
     * to get error checks and code completion for the Android project files.
     */

    public MainActivity() {
        this.mouseEventsEnabled  = true;
        //splashPicID = R.drawable.splash;
        // Set the application class to run
        appClass = "mygame.Main";
        // Try ConfigType.FASTEST; or ConfigType.LEGACY if you have problems
        //eglConfigType = ConfigType.BEST;
        // Exit Dialog title & message
        exitDialogTitle = "Exit?";
        exitDialogMessage = "Press Yes";
        // Enable verbose logging
        //eglConfigVerboseLogging = false;
        // Choose screen orientation
        //screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        // Enable MouseEvents being generated from TouchEvents (default = true)
        //mouseEventsEnabled = true;
        // Set the default logging level (default=Level.INFO, Level.ALL=All Debug Info)
        LogManager.getLogManager().getLogger("").setLevel(Level.INFO);
    }

    @Override
    public void onCreate(Bundle bundle) {

        super.onCreate(bundle);

        if (app != null) {
            AndroidManager androidManager;
            app.getStateManager().attach(new AndroidManager());
            androidManager = app.getStateManager().getState(AndroidManager.class);
            androidManager.setFilePath(getFilesDir().toString());
        }

        int androidVersion = android.os.Build.VERSION.SDK_INT;


        if (androidVersion > 10) {

            AdView adView;

            adView = new AdView(this);
            adView.setAdSize(AdSize.SMART_BANNER);
            adView.setAdUnitId("XXXXX");
            adView.buildLayer();

            LinearLayout ll = new LinearLayout(this);
            ll.setGravity(Gravity.BOTTOM);
            ll.addView(adView);
            addContentView(ll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

            AdRequest adRequest = new AdRequest.Builder()
                    .build();

            // Start loading the ad in the background.
            adView.loadAd(adRequest);
            adView.bringToFront();
            adView.requestFocus();

        }

    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        
        return true;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        System.runFinalization();
        android.os.Process.killProcess(android.os.Process.myPid());
    }

}

Should run your JME game just fine.

1 Like

I seem to have hit problems using the lighting shader. Is there another way to achieve this? My game 100% depends on shadows(the things trying to kill you are way above you, it’s the warning system.)

E/AndroidRuntime: FATAL EXCEPTION: GLThread 591
Process: com.indigoa.android.crushed, PID: 9501
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Common/MatDefs/Shadow/PostShadow.frag, defines, type=Fragment, language=GLSL100]
ERROR: 0:77: 'sampler2DShadow' : Reserved word. 
ERROR: 0:77: 'sampler2DShadow' : Syntax error:  syntax error
Error
E/AndroidRuntime: FATAL EXCEPTION: GLThread 591
    Process: com.indigoa.android.crushed, PID: 9501
    com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Common/MatDefs/Shadow/PostShadow.frag, defines, type=Fragment, language=GLSL100]
    ERROR: 0:77: 'sampler2DShadow' : Reserved word. 
    ERROR: 0:77: 'sampler2DShadow' : Syntax error:  syntax error
    INTERNAL ERROR: no main() function!
    ERROR: 2 compilation errors.  No code generated.


    at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1200)
    at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1227)
    at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1291)
    at com.jme3.material.logic.DefaultTechniqueDefLogic.render(DefaultTechniqueDefLogic.java:94)
    at com.jme3.material.Technique.render(Technique.java:166)
    at com.jme3.material.Material.render(Material.java:968)
    at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:600)
    at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
    at com.jme3.renderer.queue.RenderQueue.renderShadowQueue(RenderQueue.java:275)
    at com.jme3.shadow.AbstractShadowRenderer.postFrame(AbstractShadowRenderer.java:495)
    at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1102)
    at com.jme3.renderer.RenderManager.render(RenderManager.java:1145)
    at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
    at com.jme3.app.AndroidHarness.update(AndroidHarness.java:497)
    at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:336)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1593)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1289)

E/com.jme3.app.AndroidHarness: SEVERE Exception thrown in Thread[GLThread 591,5,main]
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Common/MatDefs/Shadow/PostShadow.frag, defines, type=Fragment, language=GLSL100]
ERROR: 0:77: ‘sampler2DShadow’ : Reserved word.
ERROR: 0:77: ‘sampler2DShadow’ : Syntax error: syntax error
INTERNAL ERROR: no main() function!
ERROR: 2 compilation errors. No code generated.

    at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1200)
    at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1227)
    at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1291)
    at com.jme3.material.logic.DefaultTechniqueDefLogic.render(DefaultTechniqueDefLogic.java:94)
    at com.jme3.material.Technique.render(Technique.java:166)
    at com.jme3.material.Material.render(Material.java:968)
    at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:600)
    at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
    at com.jme3.renderer.queue.RenderQueue.renderShadowQueue(RenderQueue.java:275)
    at com.jme3.shadow.AbstractShadowRenderer.postFrame(AbstractShadowRenderer.java:495)
    at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1102)
    at com.jme3.renderer.RenderManager.render(RenderManager.java:1145)
    at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
    at com.jme3.app.AndroidHarness.update(AndroidHarness.java:497)
    at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:336)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1593)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1289)

Album has comparison of with/without DirectionalLightShadowRenderer(so you can see why I need it.)

Edit: Could I copy the PostShadow.frag file and just rename the variable on all occurances?
Edit#2: My phone also seems to ignore app.settings.setFrameRate(30);

I’ve always used unshaded materials when doing JME applications. Can’t help you when using shaders or lighting unfortunately.

All I should need to do is copy the entire code of DLSR and ASR, and change the location of the post processing shader in the ASR to my new one which is exactly the same, but without the conflicting variable name.

P.S. How do you manage any silver-like colors using Unshaded materials?

Well I couldn’t find ‘sampler2DShadow’ in PostShadow.frag, PreShadow.frag, BasicPostShadow.frag, or Phadow.vert(I was getting desprate), so I assume it’s in

#import "Common/ShaderLib/Shadows.glsllib"
#import "Common/ShaderLib/GLSLCompat.glsllib"

Any Ideas/workarounds? I guess I could always make some bitmaps and render them on the ground as a shadow.
FPS Fix:

  1. define counter as an integer
  2. new Thread(() -> {
             while (counter > -1) {
             try {
                 Thread.sleep(1000/30); // MY Framerate(or updaterate I guess) is 30fps
                 counter++;
             } catch (InterruptedException e) {}
             }}).start();
    
    In your AppState’s init method.
  3. public int updateCounter() {
         int c = counter;
         counter = 0;
         return c;
     }
     @Override
     public void update(float tpf) {
        int uc = updateCounter();
        for (int i = 0; i < uc; i++) {
            // Your update stuff that needs to be repeatedly fired(game logic, entity updates, Etc...)
        }
        //Your updates that don't need to be repeatedly fired(UI, Guis, Hud, Etc...)
    }
    
  4. counter = -2; in cleanup method