RocketChat / Rocket.Chat.Cordova

Rocket.Chat Cross-Platform Mobile Application via Cordova (DEPRECATED)
MIT License
104 stars 109 forks source link

Solved: can't build on android #151

Open maxlinux2000 opened 7 years ago

maxlinux2000 commented 7 years ago

Hi all, I have the lastest sdk tools (android-22, 23, 24,25) and my cordova environment works fine with other apps.

$ git clone https://github.com/RocketChat/Rocket.Chat.Cordova
$ cd Rocket.Chat.Cordova
$ echo 'Bugsnag.apiKey = "my google API";' > www/js/bugsnag_apikey.js
$ echo 'window.ANDROID_SENDER_ID = "My Proj ID";' > www/shared/js/android_sender_id.js
$ npm install
$ cordova prepare
$ cordova build

and the build fail with error

* What went wrong:
Execution failed for task ':processArmv7DebugManifest'.
> Manifest merger failed : Attribute activity#com.facebook.FacebookActivity@theme value=(@android:style/Theme.Translucent.NoTitleBar) from AndroidManifest.xml:49:184-243
    is also present at [com.facebook.android:facebook-android-sdk:4.17.0] AndroidManifest.xml:32:13-63 value=(@style/com_facebook_activity_theme).
    Suggestion: add 'tools:replace="android:theme"' to <activity> element at AndroidManifest.xml:49:9-246 to override.

So I changing the version of facebook4 plugin with:

$ cordova plugin rn cordova-plugin-facebook4 $ cordova plugin add cordova-plugin-facebook4@1.7.4

and updating the config.xml with:

and adding in the $ cordova platform rm android $ cordova platform add android@5.1.1 but it still not working with this is the error: ``` Execution failed for task ':processArmv7DebugManifest'. > Manifest merger failed : Attribute activity#com.facebook.FacebookActivity@theme value=(@android:style/Theme.Translucent.NoTitleBar) from AndroidManifest.xml:49:184-243 is also present at [com.facebook.android:facebook-android-sdk:4.17.0] AndroidManifest.xml:32:13-63 value=(@style/com_facebook_activity_theme). Suggestion: add 'tools:replace="android:theme"' to element at AndroidManifest.xml:49:9-246 to override. ``` some one can solve the problem? here my android sdk ![image](https://cloud.githubusercontent.com/assets/5683921/20194631/694a1258-a793-11e6-9821-84bb9813663e.png)
g0ldstrike commented 7 years ago

I'm having the same issue. Haven't succeeded yet to successfully build this project for Android.

I also noticed that when I want to specify Android API 22 for Cordova: $ cordova platform add android@5.1.1 then Cordova targets API 23. If I continue with $ cordova build android it gives an error Please install Android target: "android-23"

I come one step further when I add android@4.1.1 instead, because Cordova then targets API 22, so the previous error does not occur, but I still get the build error you are describing.

maxlinux2000 commented 7 years ago

Ok, I solve the problem for the moment

I dropped the crosswalk-webview, upgraded the plugins facebook4 to v. 1.7.4 and googleplus to 5.1.1. and finally used android@6 (android-25) instead the old 22.

I think that we can drop down the olds smartphones before android 4.4, because they are slow and low in ram memory.

below a simple bash script in order tu test my solution, but better choice is to modify the sources here in github.

#!/bin/bash
rm -rf Rocket.Chat.Cordova
git clone https://github.com/RocketChat/Rocket.Chat.Cordova

cd Rocket.Chat.Cordova
echo 'Bugsnag.apiKey = "MyApiKey";' > www/js/bugsnag_apikey.js
echo 'window.ANDROID_SENDER_ID = "MyProjNumber";' > www/shared/js/android_sender_id.js

npm install
cordova prepare

cordova platform remove ios
cordova platform remove android
cordova platform add android@6

# drop crosswalk-webview
cordova plugin rm cordova-plugin-crosswalk-webview
cat config.xml | grep -v "cordova-plugin-crosswalk-webview" > tmp
mv tmp config.xml

#upgrade facebook4 to v. 1.7.4 
cordova plugin rm cordova-plugin-facebook4
#  (please put sed command in one line)
sed -i 's|<plugin name="cordova-plugin-facebook4" spec="1.7.0">|<plugin name="cordova-plugin-facebook4" spec="1.7.4">|' config.xml
cordova plugin add cordova-plugin-facebook4

# upgrade cordova-plugin-googleplus to 5.1.1
cordova plugin rm cordova-plugin-googleplus
#  (please put sed command in one line)
sed -i 's|<plugin name="cordova-plugin-googleplus" spec="~4.0.8">|<plugin name="cordova-plugin-googleplus" spec="5.1.1">|' config.xml
cordova plugin add cordova-plugin-googleplus@5.1.1

cordova build android
g0ldstrike commented 7 years ago

Works like a charm! Thanks a lot.

By the way, shouldn't there be one extra line just above the last line? : cordova plugin add cordova-plugin-googleplus

Furthermore I agree that updating the source would be the best solution.

maxlinux2000 commented 7 years ago

you are right! I missed to copy the line about google+. I will edit the previous message, for the others

maxlinux2000 commented 7 years ago

just correct the script. tnx.

Now, I solved another problem. The android apps need to connect with ssl, so we need to use nginx

So if someone need it, here a script that install and configure nginx

#!/bin/bash
apt-get install -y nginx
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
./certbot-auto certonly --standalone

ln -s /etc/letsencrypt/live/rocket.mrobot.eu/privkey.pem /etc/nginx/certificate.key
ln -s /etc/letsencrypt/live/rocket.mrobot.eu/fullchain.pem /etc/nginx/certificate.crt
chmod 400 /etc/nginx/certificate.key

echo '
# Upstreams
upstream backend {
    server 127.0.0.1:3000;
}

# HTTPS Server
server {
    listen 443;
    server_name YOUSERVERNAME;
    error_log /var/log/nginx/rocketchat.access.log;
    ssl on;
    ssl_certificate /etc/nginx/certificate.crt;
    ssl_certificate_key /etc/nginx/certificate.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE
    location / {
        proxy_pass http://YOUR_IP_SERVER:3000/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;
        proxy_redirect off;
    }
} ' >> /etc/nginx/sites-enabled/default
service nginx restart

It's possible that nginx doesen't works...so please listen the log at /var/log/nginx/rocketchat.access.log in order to fix any problems

and finally run the RC server with:

#!/bin/bash
cd Rocket.Chat
export MONGO_OPLOG_URL=mongodb://localhost:27017/local
export ROOT_URL=https://YourDomain.com/
export MONGO_URL=mongodb://localhost:27017/rocketchat
export PORT=3000
node main.js
migscabral commented 7 years ago

I followed the script posted by @maxlinux2000 but I still encounter the same problem.

BUILD FAILED

Total time: 5.675 secs
Error: /Users/migscabral/Documents/work/8layer/communic8/rocketchat/mobile-cordova/platforms/android/gradlew: Command failed with exit code 1 Error output:
/Users/migscabral/Documents/work/8layer/communic8/rocketchat/mobile-cordova/platforms/android/AndroidManifest.xml:50:184-243 Error:
    Attribute activity#com.facebook.FacebookActivity@theme value=(@android:style/Theme.Translucent.NoTitleBar) from AndroidManifest.xml:50:184-243
    is also present at [com.facebook.android:facebook-android-sdk:4.19.0] AndroidManifest.xml:32:13-63 value=(@style/com_facebook_activity_theme).
    Suggestion: add 'tools:replace="android:theme"' to <activity> element at AndroidManifest.xml:50:9-246 to override.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugManifest'.
> Manifest merger failed : Attribute activity#com.facebook.FacebookActivity@theme value=(@android:style/Theme.Translucent.NoTitleBar) from AndroidManifest.xml:50:184-243
    is also present at [com.facebook.android:facebook-android-sdk:4.19.0] AndroidManifest.xml:32:13-63 value=(@style/com_facebook_activity_theme).
    Suggestion: add 'tools:replace="android:theme"' to <activity> element at AndroidManifest.xml:50:9-246 to override.

Here's my updated config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="243" id="com.konecty.rocket.chat" ios-CFBundleVersion="13" version="2.5.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Rocket.Chat</name>
    <description>
        Rocket.Chat mobile application
    </description>
    <author email="support@rocket.chat" href="http://rocket.chat">
        Rocket.Chat
    </author>
    <content src="index.html" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="geo:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="market:*" />
    <access launch-external="true" origin="tel:*" />
    <access launch-external="true" origin="geo:*" />
    <access launch-external="true" origin="mailto:*" />
    <access launch-external="true" origin="sms:*" />
    <access launch-external="true" origin="market:*" />
    <access origin="file:*" />
    <access origin="blob:*" />
    <access origin="cdv:*" />
    <access origin="gap:*" />
    <access origin="*" />
    <allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />
    <allow-navigation href="data:*" />
    <platform name="android">
        <preference name="android-minSdkVersion" value="15" />
        <icon density="mdpi" src="resources/icons/platform/android/res/drawable-mdpi/appicon.png" />
        <icon density="hdpi" src="resources/icons/platform/android/res/drawable-hdpi/appicon.png" />
        <icon density="xhdpi" src="resources/icons/platform/android/res/drawable-xhdpi/appicon.png" />
        <icon density="xxhdpi" src="resources/icons/platform/android/res/drawable-xxhdpi/appicon.png" />
        <icon density="xxxhdpi" src="resources/icons/platform/android/res/drawable-xxxhdpi/appicon.png" />
        <splash density="port-mdpi" height="480" src="resources/splash/Resources/android/images/res-long-port-mdpi/default.png" width="320" />
        <splash density="port-hdpi" height="800" src="resources/splash/Resources/android/images/res-long-port-hdpi/default.png" width="480" />
        <splash density="port-xhdpi" height="960" src="resources/splash/Resources/android/images/res-long-port-xhdpi/default.png" width="640" />
        <splash density="port-xxhdpi" height="1600" src="resources/splash/Resources/android/images/res-long-port-xxhdpi/default.png" width="960" />
        <splash density="port-xxxhdpi" height="1920" src="resources/splash/Resources/android/images/res-long-port-xxxhdpi/default.png" width="1280" />
        <splash density="land-mdpi" height="320" src="resources/splash/Resources/android/images/res-long-land-mdpi/default.png" width="480" />
        <splash density="land-hdpi" height="480" src="resources/splash/Resources/android/images/res-long-land-hdpi/default.png" width="800" />
        <splash density="land-xhdpi" height="640" src="resources/splash/Resources/android/images/res-long-land-xhdpi/default.png" width="960" />
        <splash density="land-xxhdpi" height="960" src="resources/splash/Resources/android/images/res-long-land-xxhdpi/default.png" width="1600" />
        <splash density="land-xxxhdpi" height="1280" src="resources/splash/Resources/android/images/res-long-land-xxxhdpi/default.png" width="1920" />
        <preference name="Orientation" value="default" />
        <config-file parent="/*" target="AndroidManifest.xml">
            <uses-permission android:name="android.permission.RECORD_AUDIO" />
            <uses-permission android:name="android.permission.RECORD_VIDEO" />
            <uses-permission android:name="android.permission.CAMERA" />
        </config-file>
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <icon height="29" src="resources/icons/Resources/iphone/appicon-Small.png" width="29" />
        <icon height="40" src="resources/icons/Resources/iphone/appicon-Small-40.png" width="40" />
        <icon height="50" src="resources/icons/Resources/iphone/appicon-Small-50.png" width="50" />
        <icon height="57" src="resources/icons/Resources/iphone/appicon.png" width="57" />
        <icon height="58" src="resources/icons/Resources/iphone/appicon-Small@2x.png" width="58" />
        <icon height="60" src="resources/icons/Resources/iphone/appicon-60.png" width="60" />
        <icon height="72" src="resources/icons/Resources/iphone/appicon-72.png" width="72" />
        <icon height="76" src="resources/icons/Resources/iphone/appicon-76.png" width="76" />
        <icon height="80" src="resources/icons/Resources/iphone/appicon-Small-40@2x.png" width="80" />
        <icon height="87" src="resources/icons/Resources/iphone/appicon-Small@3x.png" width="87" />
        <icon height="100" src="resources/icons/Resources/iphone/appicon-Small-50@2x.png" width="100" />
        <icon height="114" src="resources/icons/Resources/iphone/appicon@2x.png" width="114" />
        <icon height="120" src="resources/icons/Resources/iphone/appicon-60@2x.png" width="120" />
        <icon height="144" src="resources/icons/Resources/iphone/appicon-72@2x.png" width="144" />
        <icon height="152" src="resources/icons/Resources/iphone/appicon-76@2x.png" width="152" />
        <icon height="167" src="resources/icons/Resources/iphone/appicon-83.5@2x.png" width="167" />
        <icon height="180" src="resources/icons/Resources/iphone/appicon-60@3x.png" width="180" />
        <splash height="480" src="resources/splash/Resources/iphone/Default.png" width="320" />
        <splash height="960" src="resources/splash/Resources/iphone/Default@2x.png" width="640" />
        <splash height="1136" src="resources/splash/Resources/iphone/Default-568h@2x.png" width="640" />
        <splash height="1334" src="resources/splash/Resources/iphone/Default-667h@2x.png" width="750" />
        <splash height="2208" src="resources/splash/Resources/iphone/Default-Portrait-736h@3x.png" width="1242" />
        <splash height="1242" src="resources/splash/Resources/iphone/Default-Landscape-736h@3x.png" width="2208" />
        <splash height="1024" src="resources/splash/Resources/iphone/Default-Portrait.png" width="768" />
        <splash height="2048" src="resources/splash/Resources/iphone/Default-Portrait@2x.png" width="1536" />
        <splash height="768" src="resources/splash/Resources/iphone/Default-Landscape.png" width="1024" />
        <splash height="1536" src="resources/splash/Resources/iphone/Default-Landscape@2x.png" width="2048" />
        <preference name="Orientation" value="all" />
        <config-file parent="ITSAppUsesNonExemptEncryption" platform="ios" target="*-Info.plist">
            <false />
        </config-file>
        <config-file parent="LSApplicationQueriesSchemes" platform="ios" target="*-Info.plist">
            <array>
                <string>fbauth</string>
            </array>
        </config-file>
        <config-file parent="NSAppTransportSecurity" platform="ios" target="*-Info.plist">
            <dict>
                <key>NSAllowsArbitraryLoads</key>
                <true />
            </dict>
        </config-file>
        <config-file parent="UIApplicationShortcutItems" platform="ios" target="*-Info.plist">
            <array>
                <dict>
                    <key>UIApplicationShortcutItemIconType</key>
                    <string>UIApplicationShortcutIconTypeAdd</string>
                    <key>UIApplicationShortcutItemTitle</key>
                    <string>Add new server</string>
                    <key>UIApplicationShortcutItemType</key>
                    <string>new</string>
                </dict>
            </array>
        </config-file>
    </platform>
    <preference name="webviewbounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="AutoHideSplashScreen" value="false" />
    <preference name="ShowSplashScreenSpinner" value="false" />
    <preference name="StatusBarOverlaysWebView" value="false" />
    <preference name="FadeSplashScreen" value="false" />
    <preference name="StatusBarStyle" value="blackopaque" />
    <preference name="StatusBarBackgroundColor" value="#000000" />
    <preference name="deployment-target" value="9.0" />
    <preference name="AndroidLaunchMode" value="singleTask" />
    <hook src="hooks/beforePrepare.js" type="before_prepare" />
    <engine name="android" spec="5.2.2" />
    <engine name="ios" spec="4.3.1" />
    <plugin name="com.meteor.cordova-update" spec="https://github.com/RocketChat/com.meteor.cordova-update" />
    <plugin name="com.verso.cordova.clipboard" spec="https://github.com/VersoSolutions/CordovaClipboard" />
    <plugin name="cordova-sharingreceptor" spec="https://github.com/burstaholic/cordova-sharingreceptor" />
    <plugin name="cordova-plugin-1password" spec="0.1.5" />
    <plugin name="cordova-plugin-3dtouch" spec="~1.3.5" />
    <plugin name="cordova-plugin-actionsheet" spec="~2.3.1" />
    <plugin name="cordova-plugin-appinfo" spec="2.1.0" />
    <plugin name="cordova-plugin-camera" spec="~2.3.1" />
    <plugin name="cordova-plugin-console" spec="1.0.5" />
    <plugin name="cordova-plugin-device" spec="1.1.4" />
    <plugin name="cordova-plugin-dialogs" spec="1.3.1" />
    <plugin name="cordova-plugin-file" spec="4.3.1" />
    <plugin name="cordova-plugin-file-transfer" spec="1.6.1" />
    <plugin name="cordova-plugin-geolocation" spec="~2.4.1" />
    <plugin name="cordova-plugin-inappbrowser" spec="1.5.0" />
    <plugin name="cordova-plugin-legacy-whitelist" spec="1.1.2" />
    <plugin name="cordova-plugin-media" spec="~2.4.1" />
    <plugin name="cordova-plugin-media-capture" spec="~1.4.1" />
    <plugin name="cordova-plugin-splashscreen" spec="4.0.1" />
    <plugin name="cordova-plugin-statusbar" spec="2.2.1" />
    <plugin name="cordova-plugin-x-socialsharing" spec="~5.1.3" />
    <plugin name="ionic-plugin-keyboard" spec="2.2.1" />
    <plugin name="phonegap-plugin-push" spec="~1.4.2" />
    <plugin name="cordova-plugin-facebook4" spec="1.7.4">
        <variable name="APP_ID" value="835103589938459" />
        <variable name="APP_NAME" value="Rocket.Chat" />
    </plugin>
    <plugin name="twitter-connect-plugin" spec="~0.6.0">
        <variable name="FABRIC_KEY" value="d28a3f04738fd742320f2ae1f2049bf85a5a6144" />
    </plugin>
    <preference name="TwitterConsumerKey" value="njl2I82AXrOo0YftZyKHyC8aV" />
    <preference name="TwitterConsumerSecret" value="2RmFsMIZmOXY4mMQ1qTuoOOcOPDVtgNMbJLPFgigaYTPpQuVVQ" />
    <plugin name="cordova-plugin-googleplus" spec="~5.1.1">
        <variable name="REVERSED_CLIENT_ID" value="com.googleusercontent.apps.673693445664-pa3k48sg81r89rn65e9rlnu4gpmm5vem" />
    </plugin>
    <plugin name="cordova-custom-config" spec="~3.1.2" />
    <plugin name="cordova-plugin-customurlscheme" spec="~4.2.0">
        <variable name="URL_SCHEME" value="clientapp-rocketchat" />
    </plugin>
</widget>

Here's the generated AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="243" android:versionName="2.5.0" package="com.konecty.rocket.chat" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTask" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="clientapp-rocketchat" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host=" " android:pathPrefix="/" android:scheme=" " />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="*/*" />
            </intent-filter>
        </activity>
        <activity android:exported="true" android:name="com.adobe.phonegap.push.PushHandlerActivity" />
        <receiver android:exported="true" android:name="com.google.android.gms.gcm.GcmReceiver" android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver>
        <service android:exported="false" android:name="com.adobe.phonegap.push.GCMIntentService">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <service android:exported="false" android:name="com.adobe.phonegap.push.PushInstanceIDListenerService">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID" />
            </intent-filter>
        </service>
        <service android:exported="false" android:name="com.adobe.phonegap.push.RegistrationIntentService" />
        <meta-data android:name="io.fabric.ApiKey" android:value="d28a3f04738fd742320f2ae1f2049bf85a5a6144" />
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id" />
        <meta-data android:name="com.facebook.sdk.ApplicationName" android:value="@string/fb_app_name" />
        <activity android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/fb_app_name" android:name="com.facebook.FacebookActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    </application>
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="25" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
</manifest>

Am I missing anything?