Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
99b70dab
Commit
99b70dab
authored
Mar 17, 2016
by
Devon Carew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle android n in the android sdk
parent
ca8dbe90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
25 deletions
+119
-25
android_sdk.dart
packages/flutter_tools/lib/src/android/android_sdk.dart
+42
-25
android_sdk_test.dart
packages/flutter_tools/test/android_sdk_test.dart
+77
-0
No files found.
packages/flutter_tools/lib/src/android/android_sdk.dart
View file @
99b70dab
...
...
@@ -11,16 +11,22 @@ import '../base/os.dart';
import
'../globals.dart'
;
// Android SDK layout:
//
// $ANDROID_HOME/platform-tools/adb
// $ANDROID_HOME/build-tools/19.1.0/aapt, dx, zipalign
// $ANDROID_HOME/build-tools/22.0.1/aapt
// $ANDROID_HOME/build-tools/23.0.2/aapt
// $ANDROID_HOME/build-tools/24.0.0-preview/aapt
// $ANDROID_HOME/platforms/android-22/android.jar
// $ANDROID_HOME/platforms/android-23/android.jar
// $ANDROID_HOME/platforms/android-N/android.jar
// TODO(devoncarew): We need a way to locate the Android SDK w/o using an environment variable.
// Perhaps something like `flutter config --android-home=foo/bar`.
// Special case some version names in the sdk.
const
Map
<
String
,
int
>
_namedVersionMap
=
const
<
String
,
int
>
{
'android-N'
:
24
};
/// Locate ADB. Prefer to use one from an Android SDK, if we can locate that.
String
getAdbPath
(
[
AndroidSdk
existingSdk
])
{
...
...
@@ -47,8 +53,6 @@ class AndroidSdk {
AndroidSdkVersion
_latestVersion
;
static
AndroidSdk
locateAndroidSdk
()
{
// TODO: Use explicit configuration information from a metadata file?
String
androidHomeDir
;
if
(
Platform
.
environment
.
containsKey
(
'ANDROID_HOME'
))
{
androidHomeDir
=
Platform
.
environment
[
'ANDROID_HOME'
];
...
...
@@ -130,11 +134,11 @@ class AndroidSdk {
.
toList
();
}
List
<
Version
>
buildTools
Versions
=
<
Version
>[];
// 19.1.0, 22.0.1, ...
List
<
Version
>
buildTools
=
<
Version
>[];
// 19.1.0, 22.0.1, ...
Directory
buildToolsDir
=
new
Directory
(
path
.
join
(
directory
,
'build-tools'
));
if
(
buildToolsDir
.
existsSync
())
{
buildTools
Versions
=
buildToolsDir
buildTools
=
buildToolsDir
.
listSync
()
.
map
((
FileSystemEntity
entity
)
{
try
{
...
...
@@ -149,25 +153,32 @@ class AndroidSdk {
// Here we match up platforms with cooresponding build-tools. If we don't
// have a match, we don't return anything for that platform version. So if
// the user only ha
ve
'android-22' and 'build-tools/19.0.0', we don't find
// the user only ha
s
'android-22' and 'build-tools/19.0.0', we don't find
// an Android sdk.
_sdkVersions
=
platforms
.
map
((
String
platform
)
{
int
sdk
Version
;
_sdkVersions
=
platforms
.
map
((
String
platform
Name
)
{
int
platform
Version
;
try
{
sdkVersion
=
int
.
parse
(
platform
.
substring
(
'android-'
.
length
));
if
(
_namedVersionMap
.
containsKey
(
platformName
))
platformVersion
=
_namedVersionMap
[
platformName
];
else
platformVersion
=
int
.
parse
(
platformName
.
substring
(
'android-'
.
length
));
}
catch
(
error
)
{
return
null
;
}
Version
buildToolsVersion
=
Version
.
primary
(
buildTools
Versions
.
where
((
Version
version
)
{
return
version
.
major
==
sdk
Version
;
Version
buildToolsVersion
=
Version
.
primary
(
buildTools
.
where
((
Version
version
)
{
return
version
.
major
==
platform
Version
;
}).
toList
());
if
(
buildToolsVersion
==
null
)
return
null
;
return
new
AndroidSdkVersion
(
this
,
platform
,
buildToolsVersion
.
toString
());
return
new
AndroidSdkVersion
(
this
,
platformVersionName:
platformName
,
buildToolsVersionName:
buildToolsVersion
.
toString
()
);
}).
where
((
AndroidSdkVersion
version
)
=>
version
!=
null
).
toList
();
_sdkVersions
.
sort
();
...
...
@@ -180,13 +191,21 @@ class AndroidSdk {
}
class
AndroidSdkVersion
implements
Comparable
<
AndroidSdkVersion
>
{
AndroidSdkVersion
(
this
.
sdk
,
this
.
androidVersion
,
this
.
buildToolsVersion
);
AndroidSdkVersion
(
this
.
sdk
,
{
this
.
platformVersionName
,
this
.
buildToolsVersionName
});
final
AndroidSdk
sdk
;
final
String
androidVersion
;
final
String
buildToolsVersion
;
int
get
sdkLevel
=>
int
.
parse
(
androidVersion
.
substring
(
'android-'
.
length
));
final
String
platformVersionName
;
final
String
buildToolsVersionName
;
int
get
sdkLevel
{
if
(
_namedVersionMap
.
containsKey
(
platformVersionName
))
return
_namedVersionMap
[
platformVersionName
];
else
return
int
.
parse
(
platformVersionName
.
substring
(
'android-'
.
length
));
}
String
get
androidJarPath
=>
getPlatformsPath
(
'android.jar'
);
...
...
@@ -205,20 +224,18 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
}
String
getPlatformsPath
(
String
itemName
)
{
return
path
.
join
(
sdk
.
directory
,
'platforms'
,
androidVersion
,
itemName
);
return
path
.
join
(
sdk
.
directory
,
'platforms'
,
platformVersionName
,
itemName
);
}
String
getBuildToolsPath
(
String
binaryName
)
{
return
path
.
join
(
sdk
.
directory
,
'build-tools'
,
buildToolsVersion
,
binaryName
);
return
path
.
join
(
sdk
.
directory
,
'build-tools'
,
buildToolsVersion
Name
,
binaryName
);
}
@override
int
compareTo
(
AndroidSdkVersion
other
)
{
return
sdkLevel
-
other
.
sdkLevel
;
}
int
compareTo
(
AndroidSdkVersion
other
)
=>
sdkLevel
-
other
.
sdkLevel
;
@override
String
toString
()
=>
'[
${sdk.directory}
, SDK version
$sdkLevel
, build-tools
$buildToolsVersion
]'
;
String
toString
()
=>
'[
${sdk.directory}
, SDK version
$sdkLevel
, build-tools
$buildToolsVersion
Name
]'
;
bool
_exists
(
String
path
,
{
bool
complain:
false
})
{
if
(!
FileSystemEntity
.
isFileSync
(
path
))
{
...
...
packages/flutter_tools/test/android_sdk_test.dart
0 → 100644
View file @
99b70dab
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:io'
;
import
'package:flutter_tools/src/android/android_sdk.dart'
;
import
'package:path/path.dart'
as
path
;
import
'package:test/test.dart'
;
import
'src/context.dart'
;
void
main
(
)
{
group
(
'android_sdk AndroidSdk'
,
()
{
Directory
sdkDir
;
tearDown
(()
{
sdkDir
?.
deleteSync
(
recursive:
true
);
});
testUsingContext
(
'parse sdk'
,
()
{
sdkDir
=
_createSdkDirectory
();
AndroidSdk
sdk
=
new
AndroidSdk
(
sdkDir
.
path
);
expect
(
sdk
.
latestVersion
,
isNotNull
);
expect
(
sdk
.
latestVersion
.
sdkLevel
,
23
);
});
testUsingContext
(
'parse sdk N'
,
()
{
sdkDir
=
_createSdkDirectory
(
withAndroidN:
true
);
AndroidSdk
sdk
=
new
AndroidSdk
(
sdkDir
.
path
);
expect
(
sdk
.
latestVersion
,
isNotNull
);
expect
(
sdk
.
latestVersion
.
sdkLevel
,
24
);
});
});
group
(
'android_sdk AndroidSdkVersion'
,
()
{
testUsingContext
(
'parse normal'
,
()
{
AndroidSdk
sdk
=
new
AndroidSdk
(
'.'
);
AndroidSdkVersion
ver
=
new
AndroidSdkVersion
(
sdk
,
platformVersionName:
'android-23'
,
buildToolsVersionName:
'23.0.0'
);
expect
(
ver
.
sdkLevel
,
23
);
});
testUsingContext
(
'parse android n'
,
()
{
AndroidSdk
sdk
=
new
AndroidSdk
(
'.'
);
AndroidSdkVersion
ver
=
new
AndroidSdkVersion
(
sdk
,
platformVersionName:
'android-N'
,
buildToolsVersionName:
'24.0.0'
);
expect
(
ver
.
sdkLevel
,
24
);
});
});
}
Directory
_createSdkDirectory
(
{
bool
withAndroidN:
false
})
{
Directory
dir
=
Directory
.
systemTemp
.
createTempSync
(
'android-sdk'
);
_createSdkFile
(
dir
,
'platform-tools/adb'
);
_createSdkFile
(
dir
,
'build-tools/19.1.0/aapt'
);
_createSdkFile
(
dir
,
'build-tools/22.0.1/aapt'
);
_createSdkFile
(
dir
,
'build-tools/23.0.2/aapt'
);
if
(
withAndroidN
)
_createSdkFile
(
dir
,
'build-tools/24.0.0-preview/aapt'
);
_createSdkFile
(
dir
,
'platforms/android-22/android.jar'
);
_createSdkFile
(
dir
,
'platforms/android-23/android.jar'
);
if
(
withAndroidN
)
_createSdkFile
(
dir
,
'platforms/android-N/android.jar'
);
return
dir
;
}
void
_createSdkFile
(
Directory
dir
,
String
filePath
)
{
File
file
=
new
File
(
path
.
join
(
dir
.
path
,
filePath
));
file
.
createSync
(
recursive:
true
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment