I would like to implement sdkbox's twitter sharing function (with images) on Android.
Android version only
sdkbox::PluginShare::init();
It will crash at the part of .
iOS is working fine.
This is the error message that I picked up the logcat below.
In addition to twitter, the fabric crashlytics (answers can be measured) also spewed errors.
Both do not seem to work properly.
`
E/CrashlyticsCore (13497): java.util.current.Exception: java.lang.NoSuchMethodError:io.fabric.sdk.android.services.common.Crash$FatalException.<init>
E/CrashlyticsCore (13497): at java.util.current.FutureTask.report (FutureTask.java:94)
E/CrashlyticsCore (13497): at java.util.current.FutureTask.get (FutureTask.java:174)
E/CrashlyticsCore (13497): at com.crashlytics.android.core.CrashlyticsExecutorServiceWrapper.executeSyncLoggingException (CrashlyticsExecutorServiceWrapper.java:44)
E/CrashlyticsCore (13497): at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtExceptionHandler.java:251)
E/CrashlyticsCore (13497): at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java: 693)
E/CrashlyticsCore (13497): at java.lang.ThreadGroup.uncaughtException (ThreadGroup.java: 690)
E/CrashlyticsCore (13497): at dalvik.system.NativeStart.main (Native Method)
E/CrashlyticsCore (13497): Caused by: java.lang.NoSuchMethodError:io.fabric.sdk.android.services.common.Crash$FatalException.<init>
E/CrashlyticsCore (13497): atcom.crashlytics.android.core.CrashlyticsCore.recordFatalExceptionEvent (CrashlyticsCore.java:715)
E/CrashlyticsCore (13497): at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.writeFatal (CrashlyticsUncaughtExceptionHandler.java:808)
E/CrashlyticsCore (13497): at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.handleUncaughtExceptionHandler.java:278)
E/CrashlyticsCore (13497): at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.access$100 (CrashlyticsUncaughtExceptionHandler.java:55)
E/CrashlyticsCore (13497): at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler $5.call (CrashlyticsUncaughtExceptionHandler.java:254)
E/CrashlyticsCore (13497): at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler $5.call (CrashlyticsUncaughtExceptionHandler.java:251)
E/CrashlyticsCore (13497): at java.util.current.FutureTask.run (FutureTask.java:234)
E/CrashlyticsCore(13497): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
E/CrashlyticsCore(13497): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
E/CrashlyticsCore(13497): at io.fabric.sdk.android.services.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:75)
E/CrashlyticsCore(13497): at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:30)
E/CrashlyticsCore(13497): at java.lang.Thread.run(Thread.java:856)
E/AndroidRuntime(13497): FATAL EXCEPTION: main
E/AndroidRuntime(13497): java.lang.IllegalAccessError: tried to access method com.twitter.sdk.android.core.TwitterCore.<init>:(Lcom/twitter/sdk/android/core/TwitterAuthConfig;)V from class com.twitter.sdk.android.Twitter
E/AndroidRuntime(13497): at com.twitter.sdk.android.Twitter.<init>(Twitter.java:65)
E/AndroidRuntime(13497): at com.sdkbox.plugin.PluginShareTwitterConnector$1.run(PluginShareTwitterConnector.java:77)
E/AndroidRuntime(13497): at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime(13497): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(13497): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(13497): at android.app.ActivityThread.main(ActivityThread.java:5159)
E/AndroidRuntime(13497): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13497): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(13497): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:810)
E/AndroidRuntime (13497): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:577)
E/AndroidRuntime (13497): at dalvik.system.NativeStart.main (Native Method)
`
`
buildscript{
repositories {
maven {url'https://maven.fabric.io/public'}
}
dependencies {
classpath'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven {url'https://maven.fabric.io/public'}
}
android{android{
compileSdkVersion23
buildToolsVersion "24"
defaultConfig {
applicationId "com.hogehogehogehoge"
minSdkVersion15
targetSdkVersion23
versionCode1
versionName "1.0.0"
multiDexEnabled true
}
dexOptions{
incremental true
javaMaxHeapSize "4096M"
jumboMode=true
preDexLibraries=false
}
sourceSets.main{
java.srcDir "src"
res.srcDir "res"
jniLibs.srcDir "libs"
manifest.srcFile "AndroidManifest.xml"
assets.srcDir "assets"
}
signingConfigs {
release {
if(project.hasProperty("RELEASE_STORE_FILE")}
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
miniEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if(project.hasProperty("RELEASE_STORE_FILE")}
signingConfig signingConfigs.release
}
}
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
}
repositories {
mavenCentral()
}
dependencies {
compilefileTree (dir: 'libs', include: ['*.jar'])
compile project (':libcocos2dx')
compile('com.twitter.sdk.android:twitter:+@aar'){
transitive=true; exclude module: 'support-v4'
}
compile('com.facebook.android:audience-network-sdk:4.15.0'){
exclude group: 'com.google.android.gms';
}
compile('com.crashlytics.sdk.android:answers:1.3.10@aar'){
transitive=true; exclude module: 'fabric'
}
compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar'){
transitive=true; exclude module: 'fabric'
}
//compile'com.android.support:multidex:1.0.1'
compile'com.google.firebase:firebase-core:10.0.1'
compile'com.google.firebase:firebase-ads:10.0.1'
}
apply plugin: 'com.google.gms.google-services'
`
`
$find. / | grep build.gradle
.//cocos2d/cocos/platform/android/java/libs/gps/build.gradle
.//cocos2d/cocos/platform/android/libcocos2dx/build.gradle
.//cocos2d/cocos/platform/android/libcocos2dx/libs/facebook_lib/build.gradle
.//cocos2d/cocos/platform/android/libcocos2dx-with-controller/build.gradle
.//proj.android-studio/app/build.gradle
.//proj.android-studio/build.gradle
`
`
package org.cocos2dx.cpp;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import org.cocos2dx.lib.Cocos2dxActivity;
importio.fabric.sdk.android.services.common.Crash;
import jp.hogehelper.ad.AdMob;
import jp.hogehelper.ad.Facebook;
import jp.hogehelper.ad.Nend;
importio.fabric.sdk.android.Fabric;
import com.crashlytics.android.answers.Answers;
import com.twitter.sdk.android.Twitter;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.crashlytics.android.crashlytics;
import com.google.firebase.analytics.FirebaseAnalytics;
import java.util.Locale;
public class AppActivity extensions Cocos2dxActivity{
private FirebaseAnalytics mFirebaseAnalytics;
// Note: Your consumer key and secret should be obfuscated in your source code before shipping.
// private static final String TWITTER_KEY="aaaaaaaaa";
// private static final String TWITTER_SECRET="bbbbbbb";
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with (this, new Twitter (authConfig));
*/
Fabric.with (this, new Crashlytics());
Fabric.with (this, new Answers());
mFirebaseAnalytics=FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.setAnalyticsCollectionEnabled(true);
}
@ Override
protected void onResume() {
super.onResume();
AdMob.getInstance().onResume();
Facebook.getInstance().onResume();
Nend.getInstance().onResume();
AdMobVideo.getInstance().onResume();
} @ Override
protected void onPause() {
AdMob.getInstance().onPause();
Facebook.getInstance().onPause();
Nend.getInstance().onPause();
AdMobVideo.getInstance().onPause();
super.onPause();
} @ Override
protected void onDestroy() {
AdMob.getInstance().onDestroy();
// Facebook.getInstance().onDestroy();
Nend.getInstance().onDestroy();
AdMobVideo.getInstance().onDestroy();
super.onDestroy();
}
/**
* @return current language.
*/
public static String getCurrentLanguage() {
if(Locale.getDefault().getLanguage().equals("zh")){
return Locale.getDefault().toString();
}
return Locale.getDefault().getLanguage();
}
/** * @return true if need reset review app state.
*/
public static boolean is NeedResetReviewAppState(){
try{
String currentAppVersion=Cocos2dxActivity.getContext().getPackageManager().getPackageInfo(Cocos2dxActivity.getContext().getPackageName(),0).versionName;
String previousVersion=SharePrefs.getInstance().getAppVersion();
if(TextUtils.isEmpty(previousVersion)) {
// first launch
SharePrefs.getInstance().setAppVersion(currentAppVersion);
return true;
} else if(previousVersion.equals(currentAppVersion)) {
// same version
} else {
// other version
SharePrefs.getInstance().setAppVersion(currentAppVersion);
return true;
}
return false;
} catch(PackageManager.NameNotFoundExceptione){
e.printStackTrace();
return false;
}
}
}
`
`
package org.cocos2dx.cpp;
import android.support.multidex.MultiDexApplication;
import com.applovin.sdk.AppLovinSdk;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import android.util.Log;
public class MultiDexHogeApplication extensions MultiDexApplication {
@ Override
public void onCreate(){
super.onCreate();
Log.d("tag_name", "soccerr_____debuglog text";
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
AppLovinSdk.initializeSdk(this);
SharePrefs.getInstance().init(this);
}
}
`
`
#include "AppDelegate.h"
# include "AppInitialize.hpp"
# include "SceneTop.hpp"
# include "SceneOpening.hpp"
# include <cocos2d.h>
# include "PluginGoogleAnalytics/PluginGoogleAnalytics.h" // GoogleAnalytics in sdkbox
# include "PluginAdMob/PluginAdMob.h"
// # include "PluginFacebook/PluginFacebook.h"
# include<PluginShare/PluginShare.h>
//# include "PluginShare/PluginShare.h"
# include "AdMobHelper.hpp"
# include "AdMobManager.hpp" // Manage the entire admob perimeter
//#import<Firebase.h>
//#import<Answers/Answers.h>
//#import<Google/Analytics.h>
// # include "AdTest.hpp"
using namespace cocos2d;
AppDelegate::AppDelegate(){}
AppDelegate::~AppDelegate(){}
// if you want a different context, just modify the value of glContextAttrs
// it will take effect on all platforms
voidAppDelegate::initGLContextAttrs(){
// set OpenGL context attributes, now can only set six attributes:
// red, green, blue, alpha, depth, stencil
# if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
GLContextAttrs glContextAttrs= {8,8,8,8,8,24,8};
#elif CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID
GLContextAttrs glContextAttrs={5,6,5,0,16,8};
#endif
GLView::setGLContextAttrs(glContextAttrs);
}
static int register_all_packages(){
return 0;// flag for packages manager
}
boolAppDelegate::applicationDidFinishLaunching(){
// initialize director
auto director=Director::getInstance();
auto glview=director->getOpenGLView();
if(!glview){
glview=GLViewImpl::create("paz");
director->setOpenGLView (glview);
}
// set FPS.the default value is 1.0/60 if you don't call this
director->setAnimationInterval (1.0/60);
// FPS View // turn on display FPS
// director->setDisplayStats(true);
// Set the design resolution
glview->setDesignResolutionSize(SCREEN_W,SCREEN_H,
ResolutionPolicy::EXACT_FIT);
register_all_packages();
// run
director->runWithScene (AppInitialize::create());
// share
// sdkbox::PluginShare::init();
# if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
// share
sdkbox::PluginShare::init();
#elif CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID
// TODO android will fall off.
sdkbox::PluginShare::init();
#endif
// sdkbox:google analytics initialization
sdkbox::PluginGoogleAnalytics::init();
sdkbox::PluginGoogleAnalytics::startSession();
return true;
}
voidAppDelegate::applicationDidEnterBackground(){
Director::getInstance()->stopAnimation();
// if you use SimpleAudioEngine, it must be pause
CocosDension::SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}
voidAppDelegate::applicationWillEnterForeground(){
Director::getInstance()->startAnimation();
CocosDension::SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}
`
I implemented the sharing function with native java code only for Android without using the plugin sharing function of sdkbox.
Permission checking after Android OS 6 was troublesome, but it was solved without any problems.
Thank you for your cooperation! m(__)m
© 2024 OneMinuteCode. All rights reserved.