Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors using php-android-cli on fedora linux #4

Closed
Iolaum opened this issue Oct 6, 2019 · 17 comments
Closed

Errors using php-android-cli on fedora linux #4

Iolaum opened this issue Oct 6, 2019 · 17 comments

Comments

@Iolaum
Copy link
Contributor

Iolaum commented Oct 6, 2019

I tried to use the project but encountered the following errors:

# Downloaded phpandroid.phar put in a folder inside $PATH and made it executable
$ phpandroid.phar create NewPipeC org.schabi.newpipe
/usr/bin/env: ‘php\r’: No such file or directory

After some googling I found this SO answer so I did:

$ tr -d '\15' < phpandroid.phar > phpandroid
$ chmod u+x phpandroid

and tried again:

$ phpandroid create NewPipeC org.schabi.newpipe
PHP Fatal error:  Uncaught PharException: phar "/home/iolaum/.local/bin/phpandroid" SHA1 signature could not be verified: broken signature in /home/iolaum/.local/bin/phpandroid:4
Stack trace:
#0 /home/iolaum/.local/bin/phpandroid(4): Phar::mapPhar()
#1 {main}
  thrown in /home/iolaum/.local/bin/phpandroid on line 4

at which point I gave up.

Environment details:

$ php -v
PHP 7.3.10 (cli) (built: Sep 24 2019 09:20:18) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.10, Copyright (c) 1998-2018 Zend Technologies
$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	Fedora
Description:	Fedora release 30 (Thirty)
Release:	30
Codename:	Thirty
@AnandPilania
Copy link
Owner

@Iolaum: hi,

tr -d '\15' < phpandroid.phar > phpandroid

changed the SHA1 signature of phar.

Actually this script is developed in windows & I'm a windows user, so I'm unaware of UNIX new line convention...

I'll modify the script ASAP for user-friendly methods.

May be till that time you can use that script from php directly, just clone the repo & use with php index create <PROJECT_NAME> <PROJECT_FQDN>... (hopefully this wil works)

Thanks

@Iolaum
Copy link
Contributor Author

Iolaum commented Oct 9, 2019

Thank you for the reply. Am a little busy with other stuff atm but will test your suggestion when I can.

@bodqhrohro
Copy link

The newline problem is still not fixed.

What is the purpose to add the shebang intended for *NIX systems and not to make it actually work?

@bodqhrohro
Copy link

Moreover, it applies also to the files that it generates, which makes the project a kind of viral, in a bad sense.

@bodqhrohro
Copy link

And also no package.xml, so I can't even build my own .phar in a straightforward way. How do you package it?

@AnandPilania
Copy link
Owner

AnandPilania commented Nov 25, 2020

The newline problem is still not fixed.

What is the purpose to add the shebang intended for *NIX systems and not to make it actually work?

check commit which reverted back the issue of new line. Just fork and replace \ & \\ with / and remove \r, or better revert back to the commit

And also no package.xml, so I can't even build my own .phar in a straightforward way. How do you package it?

You can generate your own phar using generate task from the root aka php tasks/generate_phar.php

My suggestions: Fork the repo, edit/update according to your needs, then recompile it as phar and use happily... OR/OTHERWISE please wait for 20-22 days, i'll make it more user friendly

Regards

@xandro0777
Copy link

Any progress here? Just hit the same problem.. does anyone have a fixed clone?

@Baneeishaque
Copy link
Contributor

Any progress here? Just hit the same problem.. does anyone have a fixed clone?

homeraptor/php-android-cli

This fork works on Ubuntu LTS, just tried the project creation using index.php. Please try yourself, build the phar - execute phar to create project - use gradle to build the project. If you have any issues - comment here.

@AnandPilania
Copy link
Owner

Hi, sorry for the inconvenience. Check the latest release.

Thanks

@Nos78
Copy link

Nos78 commented Dec 12, 2022

@Iolaum I know your issue was a couple years ago, but I found both the cause of this, and a solution for myself - I posted the issue here on this github repo (I hadn't noticed your post at that point in time, because the issue was closed and I only looked at open issues)

Briefly, the problem is that the stub file has Windows line endings, so when the phar archive is executed on linux, it interprets the shebang line literally as #!/usr/bin/env php\r with the \r carriage return character as part of the path pointing to php - epic fail 😆 (hex character 0D).

What I did (after trying several options, such as hexediting the phar) was simply to build the archive myself from source on my own linux box; its very simple to do, and the author has created generate_phar.php specifically for releasing new binaries of his tool. Although it was slightly more difficult than it initially seemed, because you need the vendors/ directory, which you have to copy out of the downloaded release (or have the required php libraries installed and in the path) this shouldn't be a problem anyway since you've already downloaded the archive to have encountered the issue - granted, you might have removed it since its been several years since then. Without the vendors subdirectory included in the phar archive, there will be a bunch of php reference errors when you try to run the tool, unless you happen to already have such libraries as composer, symfony, etc already installed and in your path. It was easiest for me simply to take the vendor folder from the authors release - the generate_phar.php script includes all the directories that are present, so copying vendor from the extracted release phar and into the source code root just works.

In the issue I created (issue #8) , I have listed all the steps and commands I used to fix this. In summary, they are:

  • download source from github (either clone the repo, or download the v1.0.0 source code and extract it; I did the latter)
  • download the release phar binary
  • extract the binary to your filesystem, and copy /vendor/ and all its sub-directories to where you put the source code from the github repo/zip file
  • run the generate_phar.php file to re-create the phpandroid.phar archive with CORRECT line endings!

These are just a summary of the steps I took. Takes about ~5 mins, and the detailed steps with commands you need are listed in issue #8

@Nos78
Copy link

Nos78 commented Dec 12, 2022

@bodqhrohro @xandro0777 you're asking if there is any update for this? The quick answer is, not yet, but I found an easy work-around, if you're still interested in using the tool. I raised an issue for this error, issue #8 and detailed my work around - I have to say, once you fix this annoying bloody bug, the tool is quite amazing! In hindsight, it was well worth my time investigating the bug - what else is vacation time for, other than fixing other peoples bugs? 😠 🤣

@Nos78
Copy link

Nos78 commented Dec 12, 2022

Hey @Iolaum @bodqhrohro and @xandro0777 I just created a bash script to automate the work-around, so all you have to do is download the script and run it.

https://github.com/Nos78/php-android-cli/blob/master/tasks/fix-phpandroid.sh

This script:

  • creates a temporary folder in your home directory,
  • downloads v1.0.0 release & source code,
  • extracts the vendor folder from the release binary (then deletes the downloaded binary)
  • and extracts the source code from downloaded zip (then deletes the downloaded zip.
  • moves the extracted vendor folder into the source,
  • modifies index.php to change the version number & text,
  • then executes php generate_phar.php to re-build the phpandroid.phar archive.
  • moves the archive to your $HOME directory & sets the execute bit (chmod +x)
  • then finally cleans up by removing the whole temporary directory.

Why do we need the source code zip? The compiled binary does not include the tasks/ folder, where the generate_phar.php script lives. So, yes, we could just extract the released phpandroid.phar, fix the line endings, but then we can't recompile back into a phar in the same way as it was created initially. I'd rather go through the same release process. The less hack-y steps we take, the better.

@Nos78
Copy link

Nos78 commented Dec 12, 2022

#!/usr/bin/bash
#
# Script to fix the line endings issue with https://github.com/AnandPilania/php-android-cli/
# Issue can be found at:
# - https://github.com/AnandPilania/php-android-cli/issues/4
# - https://github.com/AnandPilania/php-android-cli/issues/8
#
# This script:
# + downloads the v1.0.0 binary of phpandroid.phar (which has incorrect line endings for linux execution)
# + downloads the v1.0.0 source code (zip) for the above binary
# + extracts the vendor folder from the binary
# + re-builds the phpandroid.phar archive from source
# + cleans up!
echo -e "\033[93m *** This script creates a temporary folder, fix-phpandroid, in your home directory and downloads \033[0mphpandroid.phar (v1.0.0) binary release & its source code \033[93mfrom the official github repository at \033[94mhttps://github.com/AnandPilania/php-android-cli\n"
echo -e "\033[93mThis script relies upon the following being available:\033[0m\n * wget (\033[93musually installed by default on most Linux boxes\033[0m)\n * phar (\033[93mthis is part of phpV.X-common\033[0m; if you have php, you should have phar)\n\033[0m * unzip (\033[91mnot \033[93musually installed by default - use the pkg manager to install)\033[0m\n     sudo apt install unzip\n     sudo yum install unzip \033[93metc, use the pkg man for the flavour you use\n\n\033[91mPlease ensure you have these before continuing to execute this script.\033[0m"
read -p "Press any key to continue, or CTRL+C to quit"
mkdir ~/fix-phpandroid
cd ~/fix-phpandroid
wget https://github.com/AnandPilania/php-android-cli/releases/download/v1.0.0/phpandroid.phar
phar extract -f phpandroid.phar extracted
# clean up - don't need the broken binary any more
rm phpandroid.phar
wget https://github.com/AnandPilania/php-android-cli/archive/refs/tags/v1.0.0.zip
unzip v1.0.0.zip
mv extracted/vendor php-android-cli-1.0.0/.
rm v1.0.0.zip
cd php-android-cli-1.0.0
# Correct the version number, so we know in future that this is a modified binary, not an official release:
sed -i -e 's/v1.0.0/v1.0.99/g' index.php
sed -i -e 's/Console App/Console App [self build]/g' index.php
cd tasks
php generate_phar.php
mv phpandroid.phar ~/.
cd ../../..
# final clean up
rm -rf fix-phpandroid
echo -e "\n\033[93m *** All temporary files and folders created by this script have been deleted, including the two downloaded ones.\n\033[0m"
chmod +x ~/phpandroid.phar
echo -e "\n\033[93m *** Re-build phpandroid.phar successful.\033[0m \033[91mThe binary can be found in your home directory $HOME/phpandroid.phar. Execute permission bit has been set\033[0m:"
ls ~/phpandroid.phar -la
echo -e "\n\033[93m *** Running command line: \033[0m~/phpandroid.phar -V\n\033[91mIf the following reads \033[0m'Console App [self build] \033[92mv1.0.99\033[90m'\033[91m then the bug is fixed and your new phpandroid.phar is ready and waiting to be put into /usr/bin/ or wherever you want to put it!\033[0m"
~/phpandroid.phar -V

@Nos78
Copy link

Nos78 commented Dec 12, 2022

And also no package.xml, so I can't even build my own .phar in a straightforward way. How do you package it?

Its literally one line 😆 php generate_phar.php - to be fair, I think you where probably annoyed when you wrote this, which I can relate to, because so was I. But re-building the phar was the first thing I stumbled upon. I know, the bug shouldn't exist, but it does sadly. In the end, the work around is very easy, I've found the tool very useful now I got it working. Hope you share a similar experience.

@Nos78
Copy link

Nos78 commented Dec 12, 2022

@AnandPilania wrote:

Actually this script is developed in windows & I'm a windows user, so I'm unaware of UNIX new line convention...

You might like this: having just tested my theory, the irony is if you use Unix file endings, the windows version still works fine (unless there is something weird if you run windows in a VM)

@xandro0777
Copy link

xandro0777 commented Dec 12, 2022 via email

@Iolaum
Copy link
Contributor Author

Iolaum commented Dec 13, 2022

Thanks for looking into this. unfortunately I no longer trying to build android apps so I am not using this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants