-
Notifications
You must be signed in to change notification settings - Fork 151
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
Windows implementation of which
command is not properly stripping \r
characters from newlines
#1611
Comments
It will report " OS Error: The syntax of the filename, directory name, or volume label is incorrect. c links, path = 'D:\platform-tools\adb.exe, errno = 123" while runing the step "Detecting release version" and my location of adb is correct. Waiting for help,Thank you. |
Does this also happen when you run/build it "normally" with flutter? |
i can correctly run the command "flutter run" or "flutter build apk",so it not work for me |
I tried moving my ADB to a different drive ( @con-9 can you run |
I also tried replacing adb.exe in my Android sdk's platform tools with a symlink to adb.exe on a different drive and was able to successfully create a release that was as well. I'll wait to hear back what the results of |
Here's the result of running the command "shorebird doctor -v": Unhandled exception: |
It looks like this error is coming from Windows (see here), but it surprises me that flutter commands would work if the path to adb were invalid. What shell are you using (e.g., powershell, cmd.exe, git bash)? If powershell or cmd.exe, can you try executing |
This all looks right. Hmm, this is strange. Let me think for a bit and I'll see if I can come up with a good idea of how to pinpoint what's going on here. Our first step is probably to try to come reproduce this, ideally in a much smaller codebase (i.e., a single dart script). |
Ok, here is a dart script that I think should reproduce the issue. If you could run this and let me know what you see, that would be really helpful. The script: import 'dart:io';
void main() {
checkEnvVar('ANDROID_HOME');
checkEnvVar('ANDROID_SDK_ROOT');
checkEnvVar('USERPROFILE');
final userprofile = Platform.environment['USERPROFILE'];
if (userprofile != null) {
final userProfileSdkPath = '$userprofile\\AppData\\Local\\Android\\Sdk';
print('USERPROFILE sdk path: $userProfileSdkPath');
print(
'USERPROFILE sdk path is valid: ${isValidSdkPath(userProfileSdkPath)}',
);
final adbExecutable = checkForAdbExecutable(userProfileSdkPath);
if (adbExecutable != null) {
print('running adb');
final result = Process.runSync(adbExecutable.path, []);
print('adb output:');
print(result.stdout);
}
}
}
File? checkForAdbExecutable(String sdkPath) {
final adbPath = '$sdkPath\\platform-tools\\adb.exe';
print('checking for adb at: $adbPath');
final adbFile = File(adbPath);
print('adbFile: $adbFile');
if (adbFile.existsSync()) {
print('adbFile exists');
return adbFile;
} else {
print('adbFile does not exist');
return null;
}
}
bool isValidSdkPath(String path) {
final directory = Directory(path);
final licensesDirectory = Directory('$path\\licenses');
final platformToolsDirectory = Directory('$path\\platform-tools');
return directory.existsSync() &&
(licensesDirectory.existsSync() || platformToolsDirectory.existsSync());
}
void checkEnvVar(String envVarName) {
final value = Platform.environment[envVarName];
print('$envVarName: $value');
if (value != null) {
final directory = Directory(value);
print('$envVarName directory: $directory');
}
} What I see:
|
Sorry for the late reply i have been customed my sdk path like this: so i modified your code a bit to use my local sdk path, and that's what i see
and that's what i see without change your code:
|
is it detects the defalut adb path of the C drive in shorebird? |
Can you share you modifications? |
I just custom the sdk path in line 10,because there nothing in C:\Users\myuserName\AppData\Local\Android
|
since i migrate my android sdk location, i deleted the file in "C:\Users\myuserName\AppData\Local\Android" to reduce the C drive size |
Gotch. This code snippet was meant to extract the relevant bits of shorebird's ADB lookup into a place where we could more easily pinpoint the issue. It's good to see that hardcoding import 'dart:io';
void main() {
checkEnvVar('ANDROID_HOME');
checkEnvVar('ANDROID_SDK_ROOT');
checkEnvVar('USERPROFILE');
final userprofile = Platform.environment['USERPROFILE'];
if (userprofile != null) {
final userProfileSdkPath = '$userprofile\\AppData\\Local\\Android\\Sdk';
print('USERPROFILE sdk path: $userProfileSdkPath');
print(
'USERPROFILE sdk path is valid: ${isValidSdkPath(userProfileSdkPath)}',
);
final adbExecutable = checkForAdbExecutable(userProfileSdkPath);
if (adbExecutable != null) {
print('running adb');
final result = Process.runSync(adbExecutable.path, []);
print('adb output:');
print(result.stdout);
}
}
final sdkPathFromAapt = _androidSdkPathFromAapt();
print('sdkPathFromAapt: $sdkPathFromAapt');
if (sdkPathFromAapt != null) {
print('sdkPathFromAapt is valid: ${isValidSdkPath(sdkPathFromAapt)}');
final adbExecutable = checkForAdbExecutable(sdkPathFromAapt);
if (adbExecutable != null) {
print('running adb');
final result = Process.runSync(adbExecutable.path, []);
print('adb output:');
print(result.stdout);
}
}
final sdkPathFromAdb = _androidSdkPathFromAdb();
print('sdkPathFromAdb: $sdkPathFromAdb');
if (sdkPathFromAdb != null) {
print('sdkPathFromAdb is valid: ${isValidSdkPath(sdkPathFromAdb)}');
final adbExecutable = checkForAdbExecutable(sdkPathFromAdb);
if (adbExecutable != null) {
print('running adb');
final result = Process.runSync(adbExecutable.path, []);
print('adb output:');
print(result.stdout);
}
}
}
File? checkForAdbExecutable(String sdkPath) {
final adbPath = '$sdkPath\\platform-tools\\adb.exe';
print('checking for adb at: $adbPath');
final adbFile = File(adbPath);
print('adbFile: $adbFile');
if (adbFile.existsSync()) {
print('adbFile exists');
return adbFile;
} else {
print('adbFile does not exist');
return null;
}
}
String? _androidSdkPathFromAapt() {
print('checking for aapt');
final maybeAaptPath = which('aapt');
print('maybeAaptPath: $maybeAaptPath');
if (maybeAaptPath == null) {
return null;
}
// Resolve path to aapt if it is a symlink.
final resolvedAaptPath = File(maybeAaptPath).resolveSymbolicLinksSync();
return File(resolvedAaptPath).parent.parent.parent.path;
}
String? _androidSdkPathFromAdb() {
print('checking for adb');
final maybeAdbPath = which('adb');
print('maybeAdbPath: $maybeAdbPath');
if (maybeAdbPath == null) {
return null;
}
// Resolve path to adb if it is a symlink.
final resolvedAdbPath = File(maybeAdbPath).resolveSymbolicLinksSync();
return File(resolvedAdbPath).parent.parent.path;
}
String? which(String executableName) {
final result = Process.runSync('where.exe', [executableName]);
if (result.exitCode != 0) {
return null;
}
// By default, where.exe will list all matching executables on PATH. We want
// to return the first one.
return (result.stdout as String).split('\n').firstOrNull;
}
bool isValidSdkPath(String path) {
final directory = Directory(path);
final licensesDirectory = Directory('$path\\licenses');
final platformToolsDirectory = Directory('$path\\platform-tools');
return directory.existsSync() &&
(licensesDirectory.existsSync() || platformToolsDirectory.existsSync());
}
void checkEnvVar(String envVarName) {
final value = Platform.environment[envVarName];
print('$envVarName: $value');
if (value != null) {
final directory = Directory(value);
print('$envVarName directory: $directory');
}
} |
A less rigorous approach is replace the carriage return with an empty string like this(the method _androidSdkPathFromAapt will have the same problem):
then it will correctly run:
maybe there's a better way |
@con-9 Can you try setting your |
It is work for me However, it would be better to fix the method of getting the adb path, as not everyone will configure the environment exactly as expected |
which
command is not properly stripping \r
characters from newlines
The text was updated successfully, but these errors were encountered: