i have a problem with my Android App. I created an app in Libgdx with Google services and Admob. If i set debuggable to false the App just shows a black screen and the adverts on my Phone (Android 6.0.1)... But it works if i set debuggable to true. I tested that with 1 other Phone(Android 7.0) and Emulator at both it works well.
Edit2: ok tested again: It only works in Emulator Btw: im using Android Studio
I tried to uninstall the app/restart the phone.
EDIT:
here is my code:
build.gradle (android):
android {
signingConfigs {
config {
keyAlias '*****'
keyPassword '*****'
storeFile file('******')
storePassword '******'
}
}
buildToolsVersion '26.0.1'
compileSdkVersion 26
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
packagingOptions {
exclude 'META-INF/robovm/ios/robovm.xml'
}
defaultConfig {
applicationId "*****"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
signingConfig signingConfigs.config
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
signingConfig signingConfigs.config
}
}
productFlavors {
}
}
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/arm64-v8a/").mkdirs();
file("libs/x86_64/").mkdirs();
file("libs/x86/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if(outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def sdkDir = properties.getProperty('sdk.dir')
if (sdkDir) {
path = sdkDir
} else {
path = "$System.env.ANDROID_HOME"
}
} else {
path = "$System.env.ANDROID_HOME"
}
def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.*******/AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}
jdt {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
classpath {
plusConfigurations += [ project.configurations.compile ]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [ COMPILE: [plus:[project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value:"true")
}
}
}
}
}
}
}
dependencies {
compile project(':core')
compile project(':BaseGameUtils')
}
build.gradle (BaseGameUtils):
apply plugin: 'com.android.library'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
dependencies {
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('appcompat_library_version')) {
ext.appcompat_library_version = '25.3.+'
}
if (!project.hasProperty('support_library_version')) {
ext.support_library_version = '25.3.+'
}
if (!project.hasProperty('gms_library_version')) {
ext.gms_library_version = '11.0.4'
}
compile "com.android.support:appcompat-v7:${appcompat_library_version}"
compile "com.android.support:support-v4:${support_library_version}"
compile "com.google.android.gms:play-services-games:${gms_library_version}"
compile "com.google.android.gms:play-services-plus:${gms_library_version}"
}
android {
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('android_compile_version')) {
ext.android_compile_version = 25
}
if (!project.hasProperty('android_version')) {
ext.build_tools_version = "25.0.2"
}
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('android_min_sdk_version')) {
// Google Play Services minimum requirements is 14
ext.android_min_sdk_version = 14
}
compileSdkVersion android_compile_version
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion android_min_sdk_version
targetSdkVersion android_compile_version
}
}
AndroidLauncher:
package com.*****;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;
import com.google.android.gms.games.Games;
import com.google.example.games.basegameutils.GameHelper;
import com.*****.R;
public class AndroidLauncher extends AndroidApplication implements AdHandler,PlayServices {
@Override
protected void onPause() {
super.onPause();
rewardedAd.pause(this);
adView.pause();
}
@Override
protected void onResume() {
super.onResume();
adView.resume();
rewardedAd.resume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
adView.destroy();
rewardedAd.destroy(this);
log("destroy", "android");
}
//Play Service
private GameHelper gameHelper;
private final static int requestCode = 1;
//AD'S
private static final String TAG = "AndroidLauncher";
private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;
private final int SHOW_BIG_ADS = 3;
private final int HIDE_BIG_ADS = 2;
private final int SHOW_REWARD_ADS = 5;
private final int HIDE_REWARD_ADS = 4;
protected AdView adView;
protected InterstitialAd interstitialAd;
private boolean interstitialLoaded = false;
protected RewardedVideoAd rewardedAd;
private String rewardType;
private int beforeReward;
private boolean rewardedIsLoaded = false;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SHOW_ADS:
adView.setVisibility(View.VISIBLE);
break;
case HIDE_ADS:
adView.setVisibility(View.GONE);
break;
case SHOW_BIG_ADS:
if (interstitialLoaded) {
interstitialAd.show();
}
break;
case HIDE_BIG_ADS:
break;
case SHOW_REWARD_ADS:
if (rewardedAd.isLoaded()) {
rewardedAd.show();
} else {
loadRewardedVideoAd();
}
break;
}
}
};
@Override
public boolean rewardIsLoaded() {
return rewardedIsLoaded;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Play Services
gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
gameHelper.enableDebugLog(false);
GameHelper.GameHelperListener gameHelperListener = new GameHelper.GameHelperListener()
{
@Override
public void onSignInFailed(){ }
@Override
public void onSignInSucceeded(){ }
};
//AD'S
MobileAds.initialize(this, "*******");
rewardedAd = MobileAds.getRewardedVideoAdInstance(this);
rewardedAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded() {
rewardedIsLoaded = true;
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
rewardedIsLoaded = false;
}
@Override
public void onRewardedVideoAdClosed() {
loadRewardedVideoAd();
}
@Override
public void onRewarded(RewardItem rewardItem) { }
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
rewardedIsLoaded = false;
loadRewardedVideoAd();
}
});
loadRewardedVideoAd();
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("********");
final AdRequest adRequest = new AdRequest.Builder().addTestDevice("********")
.build();
interstitialAd.loadAd(adRequest);
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
interstitialLoaded = true;
}
@Override
public void onAdClosed() {
super.onAdClosed();
interstitialLoaded = false;
interstitialAd.loadAd(adRequest);
}
});
RelativeLayout layout = new RelativeLayout(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
View gameView = initializeForView(new com.marcol.colorion.Gaming(this,this), config);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
adView = new AdView(this);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
}
});
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("*********");
AdRequest.Builder builder = new AdRequest.Builder();
builder.addTestDevice("*********");
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
RelativeLayout.LayoutParams gameParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
gameParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
log("add", "GameView");
layout.addView(gameView, gameParams);
layout.addView(adView, adParams);
adView.loadAd(builder.build());
setContentView(layout);
//initialize(new Gaming(), config);
gameHelper.setup(gameHelperListener);
}
private void loadRewardedVideoAd() {
rewardedAd.loadAd("**********", new AdRequest.Builder()
.addTestDevice("*************").build());
}
@Override
public void showAds(boolean show) {
handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
}
@Override
public void showBigAd(boolean show) {
handler.sendEmptyMessage(show ? SHOW_BIG_ADS : HIDE_BIG_ADS);
}
@Override
public void showRewardAd(boolean show, String rewardType, int beforeReward) {
this.rewardType = rewardType;
this.beforeReward = beforeReward;
handler.sendEmptyMessage(show ? SHOW_REWARD_ADS : HIDE_REWARD_ADS);
}
//Play Services
@Override
protected void onStart() {
super.onStart();
gameHelper.onStart(this);
}
@Override
protected void onStop() {
super.onStop();
gameHelper.onStop();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
gameHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void signIn() {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
gameHelper.beginUserInitiatedSignIn();
}
});
} catch (Exception e) {
Gdx.app.log("MainActivity", "Log in failed: " + e.getMessage() + ".");
}
}
@Override
public void signOut() {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
gameHelper.signOut();
}
});
} catch (Exception e) {
Gdx.app.log("MainActivity", "Log out failed: " + e.getMessage() + ".");
}
}
@Override
public void rateGame() {
String str = "Your PlayStore Link";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
}
@Override
public void unlockAchievement() {
/* Games.Achievements.unlock(gameHelper.getApiClient(),
getString(R.string.achievement_dum_dum));*/
}
@Override
public void submitScore(int highScore) {
if (isSignedIn() == true) {
Games.Leaderboards.submitScore(gameHelper.getApiClient(),
getString(R.string.leaderboard_highscores), highScore);
}
}
@Override
public void showAchievement() {
if (isSignedIn() == true) {
startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), requestCode);
} else {
signIn();
}
}
@Override
public void showScore() {
if (isSignedIn() == true) {
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(),
getString(R.string.leaderboard_highscores)), requestCode);
} else {
signIn();
}
}
@Override
public boolean isSignedIn() {
return gameHelper.isSignedIn();
}
}
I hope any 1 can help me.
Thank you :) Discor
ok I fixed it:
Never call a HTTP Request in main Thread :D
"On Android: You cannot access the network on the main thread without disabling strict mode. This is done to prevent network operations from hanging the main thread. See here",
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.