前回まったく歯が立たなかったCCSocialShareです。
昨日審査出した新作でも、Android版は実装できませんでした。
ですから、今度はまったく新しいプロジェクトで試してみようとおもいます。
はっじめっるよー
まずはプロジェクトの作成。
cocos new test -p xyz.owlsoft.test -l cpp -d ~/Desktop
ここまではもう慣れたものです。
そして、一応実機にビルドしておきます。
cd ~/Desktop/test cocos run -p android --android-studio
→めんどうくさいので画像はないけど無事ビルド完了。
さて、ここからです。
公式マニュアルを読みながらすすめます。
https://github.com/giginet/CCSocialShare/blob/master/README.md#how-to-integrate
ファイルのダウンロード
$ git clone https://github.com/giginet/CCSocialShare.git Classes/external/CCSocialShare
そういや、Githubの使い方だとか、その辺まったくわかんないんだよね。
有料版が安くなった!とか言ってたけど、何に使うんだろうw
そして、Android-Studioを開いていろいろいじっていきます。
・Android-Studioのsetting.gradleを編集。
// Add this setting
include ':socialshare'
project(':socialshare').projectDir = new File(settingsDir, '../Classes/external/CCSocialShare/CCSocialShare/android')
そして一応SyncNow
たぶん、socialshareのプロジェクトをAndroid-Studioに表示させるてきな。
・アプリのbuild.gradle内、dependenciesを編集。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libcocos2dx')
// Add this line
compile project(':socialshare')
}
たぶん、socialshareのプロジェクトをコンパイルしますよ、みたいな。
→Sync Now
するとエラー。
これは毎回でてるやつですね。
gradle-wrapper.properties内、「distributionUrl」を編集。
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
→Sync Now
・Android.mkを編集。
書いてる通りに、cppを読み込むやつを書く。
・ソースファイルを修正。
HelloWorldScene.cpp内の、menuCloseCallbackに実装しましょう。
void HelloWorld::menuCloseCallback(Ref* pSender)
{
if (CCSocialShare::SocialManager::isAvailable(CCSocialShare::Service::TWITTER)) {
Size size = Director::getInstance()->getWinSize();
RenderTexture* texture = RenderTexture::create((int)size.width, (int)size.height);
texture->setPosition(Point(size.width / 2, size.height / 2));
texture->begin();
Director::getInstance()->getRunningScene()->visit();
texture->end();
texture->saveToFile("screenshot.png",
Image::Format::PNG,
true,
[&](RenderTexture* rt, const std::string& path) {
CCSocialShare::SocialManager::postMessage(CCSocialShare::Service::TWITTER,
"I beat this game!",
path.c_str(), [](CCSocialShare::PostResult result) {
if (result == CCSocialShare::PostResult::SUCCEED) {
// When to post is succeed
log("Done");
} else if (result == CCSocialShare::PostResult::CANCELED) {
// When to post is canceled
log("Canceled");
}
});
});
}
}
公式からそのままコピーです。
Android-Studioでビルドしてみます。
→落ちる。
リベンジ失敗・・・


コメントを残す