I want to run a task in gradle which will pull a file placed on Android device sdcard.
Below is the code I am trying.
File copyFile = new File("/storage/emulated/0/abc.png")
project.logger.warn("copy file path:"+copyFile.getAbsolutePath())
if (copyFile.exists()) {
project.logger.warn("file exist:yes")
}else{
project.logger.warn("file exist:no")
}
The problem is the file exists on sdcard, still I get the message in else part "file exist:no".
Can anyone help me to get the file on sdcard?
Gradle runs on your development machine. It not running on your Android device. Your development machine does not have a /storage/emulated/0/abc.png file.
You are welcome to try to have Gradle run an adb pull command to pull the file from the device to your development machine. This Gradle plugin may make this task easier, though I have not tried it.
Related
I have the following lines in my build.gradle file of my Android project:
"./prebuild.sh".execute()
But during the build I get this error:
java.io.IOException: Cannot run program "./prebuild.sh": error=2, No such file or directory
The prebuild.sh script is in the root directory of the app and executable.
What's weird is that this exact build works for everyone on the team, just not on my machine (M1). I also remember that this used to work months ago.
This happens on a fresh clone of the repository and a fresh install of Android Studio.
I think I've narrowed it down to a problem with the working directory. If I try to print it like this:
println new File(".").absolutePath
I get the following:
/Users/ale/.gradle/daemon/6.5/.
Which is obviously not my project directory.
Any hints on what I could do to fix it?
Assuming a functional shell prompt; pass the absolute path instead of . current working directory:
if(rootProject.file('prebuild.sh').exists()) {
commandLine 'sh', rootProject.file('prebuild.sh').absolutePath
} else {
println "missing: prebuild.sh"
}
Or how you start it as process, one can also pass the current working directory as second argument:
def proc = "./prebuild.sh".execute([], rootProject.absolutePath)
proc.waitForProcessOutput(System.out, System.err)
I'd run cd first, then pwd should return the expected value:
def proc = "cd ${rootProject.absolutePath} && pwd".execute()
...
Check if the file has DOS line endings (\r\n). This can lead to a confusing "no such file or directory", because it searches for a file called /bin/sh\r (ending with an actual carriage return), which does not exist.
I start a shell script using process builder. This has been working fine for days now but today, when I uploaded my files to bitbucket and messed around with them, everything seems to work again except that the ProcessBuilder which can't find the file which is already there:
val processBuilder = ProcessBuilder().command(
filesDir.absolutePath + File.separator + "start.sh").start()
The start.sh script is already in the app's files directory but I'm receiving:
java.io.IOException: Cannot run program "/data/user/0/com.example.project/files/start.sh": error=2, No such file or directory
I've tried to run it like this:
val processBuilder = ProcessBuilder().command("start.sh", filesDir.absolutePath + File.separator).start()
and then I'm receiving access denied although all files have chmod 777 and this file has even a+rx flags.
Well this will not likely help anyone but here is what happened:
I tried to put my code on bitbucket and in the process, I managed to delete everything from my local folder. Luckily my code was still on Bitbucket so I just downloaded a tar file with it and started from scratch. On my second attempt, I managed to do everything correctly but I used the downloaded sources from Bitbucket. Everything was fine except that apparently, when I imported the project directly from Bitbucket, the EOL sequence of the synced/downloaded shell script file changed to CRLF instead of LF... I resaved the file with LF and the problem was solved afterwards.
I'm about to rename a file inside /system/lib folder, however everytime i run the code below on Android, the file name still the same and nothing change.
This code works on local storage file. The phone I used is Note3 and it's rooted. I try to rename this file using app called ES file manager app and I was able to do so. But not using this code.
String shellCommand = "su mv /system/lib/libft2.so /system/lib/libft2.sok";
Runtime.getRuntime().exec(shellCommand);
Could you help me what could be wrong here or something needs to be improved/add?
I am trying to copy image file to backup it on my desktop which is linux mint (17.3 or Rosa) installed. I am using Infinix X510 phone with the newest version of android 6. At the beginning it was OK. But, at the end i get the message
“libmtp error: Could not get file from device”
I tried the solution as found by Googling here https://askubuntu.com/questions/879029/libmtp-error-could-not-get-file-from-device-on-attempting-to-transfer-files
But, it wasn't working for me. Is there a way to solve this matter? I need file to support my company job which supplying cosmetics.
Try compressing the file to a compressed format(tar,zip).Copy the file and then decompress it.
Changing the filename was the solution for me e.g: file.mkv to file.zip
Try to rename file, make sure file name not contain (-) (:) etc. Just rename it to alphabet
I have installed QPython in my Android mobile.
I written a statement in the QEdit to read a text file from the below path
/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt
I used the below statement
fob=open('/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt','r')
fob.read()
If I run the statement, it is throwing error as:
IOError:[Errno 2] No such file or directory: '/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt'
1|uo_a116#cancro:/ $
Is the above statement correct?
fob=open('File1.txt','r')
Is not working in version 1.0.4.
fout=open('File2.txt','w')
Was working on version 0.9.6, but is not working in 1.0.4.
The "error" is Read only file system.
It looks like restrictions in the (new 1.0.4) file system library. I post a mail to the editor, but no answer at this time.
For testing, try to write absolute path to your files pointing, for example, to sdcard (/sdcard/out.txt).
I had problems on this versions (>=1.0.4) because launch process of script changes and execution directory is not the same as script directory.
I had to change my scripts to point to absolute paths.
It was tested with qpython developer.
Check this link:
https://github.com/qpython-android/qpython.org/issues/48
You can also try as simple as:
fob=open('File1.txt','r')
fob.read()
Just if the script is in the same folder of the file.
You can change the current working directory to path with script before read file:
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))