├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── me
│ │ │ └── weyye
│ │ │ └── demo
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── me
│ │ │ └── weyye
│ │ │ └── demo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── me
│ │ └── weyye
│ │ └── demo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── hilocation
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── java
│ │ │ └── me
│ │ │ │ └── weyye
│ │ │ │ └── hilocation
│ │ │ │ ├── LocationListener.java
│ │ │ │ ├── SimpleLocationListener.java
│ │ │ │ └── HiLocation.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── me
│ │ │ └── weyye
│ │ │ └── demo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── me
│ │ └── weyye
│ │ └── demo
│ │ └── ExampleInstrumentedTest.java
├── libs
│ └── AMap_Location_V3.4.0_20170427.jar
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshot
├── app-debug.apk
├── QQ截图20170525161133.png
├── QQ截图20170525161647.png
├── QQ截图20170525162318.png
├── QQ截图20170525162508.png
├── QQ截图20170525162604.png
├── QQ截图20170525162907.png
├── QQ截图20170525163020.png
├── QQ截图20170525163417.png
├── QQ截图20170525173227.png
├── QQ截图20170525173828.png
└── QQ截图20170525174034.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── amap.md
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/hilocation/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':hilocation'
2 |
--------------------------------------------------------------------------------
/screenshot/app-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/app-debug.apk
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HiLocation
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525161133.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525161133.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525161647.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525161647.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525162318.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525162318.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525162508.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525162508.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525162604.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525162604.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525162907.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525162907.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525163020.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525163020.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525163417.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525163417.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525173227.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525173227.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525173828.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525173828.png
--------------------------------------------------------------------------------
/screenshot/QQ截图20170525174034.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/screenshot/QQ截图20170525174034.png
--------------------------------------------------------------------------------
/hilocation/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HiLocation
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/hilocation/libs/AMap_Location_V3.4.0_20170427.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yiqdjog1/HiLocation/HEAD/hilocation/libs/AMap_Location_V3.4.0_20170427.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/hilocation/src/main/java/me/weyye/hilocation/LocationListener.java:
--------------------------------------------------------------------------------
1 | package me.weyye.hilocation;
2 |
3 | import com.amap.api.location.AMapLocation;
4 | import com.amap.api.location.AMapLocationClient;
5 |
6 | /**
7 | * Created by Administrator on 2017/5/26 0026.
8 | */
9 |
10 | public interface LocationListener {
11 | void onSuccess(AMapLocation aMapLocation);
12 |
13 | void onError(AMapLocationClient locationClient, AMapLocation aMapLocation);
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/test/java/me/weyye/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.weyye.demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/hilocation/src/test/java/me/weyye/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.weyye.demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/hilocation/src/main/java/me/weyye/hilocation/SimpleLocationListener.java:
--------------------------------------------------------------------------------
1 | package me.weyye.hilocation;
2 |
3 | import com.amap.api.location.AMapLocation;
4 | import com.amap.api.location.AMapLocationClient;
5 |
6 | /**
7 | * Created by Administrator on 2017/5/26 0026.
8 | */
9 |
10 | public abstract class SimpleLocationListener implements LocationListener{
11 | @Override
12 | public void onError(AMapLocationClient locationClient, AMapLocation aMapLocation) {
13 | locationClient.stopLocation();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/hilocation/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/me/weyye/demo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package me.weyye.demo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("me.weyye.hilocation", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/hilocation/src/androidTest/java/me/weyye/demo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package me.weyye.demo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("me.weyye.hilocation.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 | defaultConfig {
7 | applicationId "me.weyye.demo"
8 | minSdkVersion rootProject.ext.minSdk
9 | targetSdkVersion rootProject.ext.targetSdk
10 | versionCode rootProject.ext.version_code
11 | versionName rootProject.ext.version_name
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.1.0'
28 | testCompile 'junit:junit:4.12'
29 | compile project(':hilocation')
30 | compile 'me.weyye.hipermission:library:1.0.6'
31 | }
32 |
--------------------------------------------------------------------------------
/hilocation/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/amap.md:
--------------------------------------------------------------------------------
1 | ## 分析
2 |
3 | 在我们使用高德定位sdk的时候需要在注册一个services,像这样
4 |
5 | ``` java
6 |
7 | ```
8 | 那么我打算从这个`APSService`入手
9 |
10 | 我们先来用Jadx导入jar包反编译看下目录结构:
11 |
12 | 
13 |
14 | 看到这几个类没有混淆,轻松的找到了`APSService`
15 |
16 | 打开APSService,我们可以看到在`onCreate()`使用代理模式创建了实现`APSServiceBase` 的`Service`
17 |
18 | 
19 |
20 | `APSServiceBase`既然是个接口,那么我们来找下它的实现类是谁
21 |
22 | 
23 |
24 | 我们右键这个接口名点击`Find Usage`,可以看到f.class实现了它
25 |
26 | 
27 |
28 | 我们打开这个类看下,发现启动这个service的时候传入了3个值,这3个值是不是就是高德需要的那3个参数呢?
29 |
30 | 
31 |
32 |
33 | 既然是`intent.getStringExtra("a");`,那么肯定会调用`putExtra()`,我们来全局搜下
34 |
35 |
36 | 
37 |
38 | 这个3不正是f.class取出来的这3个参数吗?我们双击打开看下
39 |
40 | 
41 |
42 | 发现有个眼熟东西`getAPIKEY()`,初步可以断定就是我们`AndroidManifest`里填写的key,我们再来看看`b`传过去的是什么
43 |
44 | 
45 |
46 | 可以看到`getPackageName();`获取了包名。
47 |
48 | 也就是说现在`a`传过去的是key,`b`传过去的是包名,那么毫无疑问`d`应该就是签名的sha1值了
49 |
50 | 那么既然找到这个地方了,我们就直接在里面写死
51 |
52 | ## 修改jar
53 |
54 | 使用 Android Studio 新建一个 Android Library 的 Module ,包名与 jar 包要修改的类包名相同,新建一个类,与要修改的类名相同
55 |
56 | 然后复制里面的代码到我们新建的类中
57 |
58 | >复制后可能会报很多错,所以我们得对着Jadx一点一点的修改这些错
59 |
60 | 修复这些错后,填上我们在高德后台创建的数据
61 |
62 | 
63 |
64 | ok,现在我们来打包生成jar包
65 |
66 | 点击Build-Make Project
67 |
68 | 
69 |
70 | build成功之后我们找到这个我们生成的`classes.jar`
71 |
72 | 
73 |
74 |
75 | 然后我们用压缩软件打开`classes.jar`和`AMap_Location_V3.4.0_20170427.jar`
76 |
77 | 找到生成的class文件替换`AMap_Location_V3.4.0_20170427.jar`里面的的class
78 |
79 | ok,这样就我们大功告成了,以后再也不用申请key了!
80 |
81 | >每个版本的代码以及破解方式不一样,这里只是提供思路,仅供参考!
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HiLocation
2 | 一个基于高德定位sdk封装的定位库,无需配置免key
3 |
4 | # 起因
5 |
6 | 现在几乎每个App都有定位,而一般为了简单我们会选择一些第三方定位sdk,像腾讯定位,百度定位以及高德定位
7 | 虽说是简单了不少,但是每次申请key,配置很繁琐。于是出现了`HiLocation`,无需繁琐的配置,一行代码搞定,就是这么任性!
8 |
9 | > 其实这个也没啥技术含量,只是破解高德定位sdk验证机制,基于它封装了一层,不喜勿喷!
10 |
11 | # 初衷
12 | 只为大家更简单更方便的集成定位sdk,**我会不定时更新定位sdk**。[点击查看原理](/amap.md)
13 |
14 | # Demo
15 | [点击下载](/app-debug.apk)
16 |
17 | # 使用
18 |
19 | ## Step1
20 | ``` java
21 | dependencies {
22 | ...
23 | compile 'me.weyye:hilocation:1.0.2'
24 | }
25 | ```
26 | ## Step2
27 |
28 | ### 开始定位
29 |
30 | ``` java
31 | HiLocation.with(MainActivity.this).callBack(MainActivity.this).interval(1000).start();//每个1秒定位一次
32 | ```
33 | 如果只定位一次可以调用`onceLocation()`
34 |
35 | ``` java
36 | HiLocation.with(MainActivity.this).callBack(MainActivity.this).onceLocation().start();//只定位一次
37 | ```
38 |
39 | 回调
40 |
41 | ``` java
42 | @Override
43 | public void onSuccess(AMapLocation amapLocation) {
44 | //定位成功回调信息,设置相关消息
45 | amapLocation.getLocationType();//获取当前定位结果来源,如网络定位结果,详见定位类型表
46 | amapLocation.getLatitude();//获取纬度
47 | amapLocation.getLongitude();//获取经度
48 | amapLocation.getAccuracy();//获取精度信息
49 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
50 | Date date = new Date(amapLocation.getTime());
51 | df.format(date);//定位时间
52 | Log.i("tag", amapLocation.toString());
53 | Toast.makeText(MainActivity.this, amapLocation.toString(), Toast.LENGTH_SHORT).show();
54 | }
55 |
56 | @Override
57 | public void onError(AMapLocationClient locationClient, AMapLocation amapLocation) {
58 | //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。
59 | Log.e("AmapError", "location Error, ErrCode:"
60 | + amapLocation.getErrorCode() + ", errInfo:"
61 | + amapLocation.getErrorInfo());
62 | HiLocation.getInstance().stop();//停止定位
63 | }
64 | ```
65 |
66 | ### 结束定位
67 |
68 | ``` java
69 | HiLocation.with(MainActivity.this).stop();
70 | //或者
71 | //HiLocation.getInstance().stop();
72 | ```
73 |
74 | ## Step3
75 | 在合适的时间调用onDestory(),比如`Activity`
76 | ``` java
77 | @Override
78 | protected void onDestroy() {
79 | super.onDestroy();
80 | HiLocation.with(MainActivity.this).onDestory();
81 | //或者
82 | //HiLocation.getInstance().onDestory();
83 | }
84 | ```
85 | ## 注意
86 |
87 | * 6.0以上手机需要自己主动申请**定位和存储权限**
88 |
89 | * 使用过程中6.0以上手机Logcat可能会看到报错`SecurityException` 缺少READ_PHONE_STATE权限。如果你不想看到这个错可以手动申请该权限
90 |
91 |
92 |
93 | 当然,为了保证我们在使用权限的时候没有后顾之忧,建议大家在每次启动app的时候申请一些常用权限,详情可以看[HiPermission](https://github.com/yewei02538/HiPermission)
94 |
95 | # 最后
96 |
97 | 如果这个对你有帮助,就给个star呗~
98 |
99 | # 联系我
100 |
101 | * QQ:505141450
102 | * Email:[hiweyye@gmail.com](mailto:hiweyye@gmail.com)
103 | * My Blog:[http://weyye.me](http://weyye.me)
104 | * 简书:[http://www.jianshu.com/u/c5da2f9c87fb](http://www.jianshu.com/u/c5da2f9c87fb)
105 | * CSDN:[http://blog.csdn.net/yewei02538](http://blog.csdn.net/yewei02538)
106 |
107 | # License
108 | Copyright (C) 2017 WeyYe
109 |
110 | Licensed under the Apache License, Version 2.0 (the "License");
111 | you may not use this file except in compliance with the License.
112 | You may obtain a copy of the License at
113 |
114 | http://www.apache.org/licenses/LICENSE-2.0
115 |
116 | Unless required by applicable law or agreed to in writing, software
117 | distributed under the License is distributed on an "AS IS" BASIS,
118 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
119 | See the License for the specific language governing permissions and
120 | limitations under the License.
121 |
--------------------------------------------------------------------------------
/app/src/main/java/me/weyye/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package me.weyye.demo;
2 |
3 | import android.Manifest;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Toast;
9 |
10 | import com.amap.api.location.AMapLocation;
11 | import com.amap.api.location.AMapLocationClient;
12 |
13 | import java.text.SimpleDateFormat;
14 | import java.util.ArrayList;
15 | import java.util.Date;
16 | import java.util.List;
17 |
18 | import me.weyye.hilocation.HiLocation;
19 | import me.weyye.hilocation.LocationListener;
20 | import me.weyye.hipermission.HiPermission;
21 | import me.weyye.hipermission.PermissionCallback;
22 | import me.weyye.hipermission.PermissionItem;
23 |
24 | public class MainActivity extends AppCompatActivity implements LocationListener, View.OnClickListener {
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | findViewById(R.id.tvStart).setOnClickListener(this);
32 | findViewById(R.id.tvStop).setOnClickListener(this);
33 |
34 | }
35 |
36 | @Override
37 | protected void onDestroy() {
38 | super.onDestroy();
39 | HiLocation.with(MainActivity.this).onDestory();
40 | }
41 |
42 | @Override
43 | public void onSuccess(AMapLocation amapLocation) {
44 | //定位成功回调信息,设置相关消息
45 | amapLocation.getLocationType();//获取当前定位结果来源,如网络定位结果,详见定位类型表
46 | amapLocation.getLatitude();//获取纬度
47 | amapLocation.getLongitude();//获取经度
48 | amapLocation.getAccuracy();//获取精度信息
49 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
50 | Date date = new Date(amapLocation.getTime());
51 | df.format(date);//定位时间
52 | Log.i("tag", amapLocation.toString());
53 | Toast.makeText(MainActivity.this, amapLocation.toString(), Toast.LENGTH_SHORT).show();
54 | }
55 |
56 | @Override
57 | public void onError(AMapLocationClient locationClient, AMapLocation amapLocation) {
58 | //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。
59 | Log.e("AmapError", "location Error, ErrCode:"
60 | + amapLocation.getErrorCode() + ", errInfo:"
61 | + amapLocation.getErrorInfo());
62 | HiLocation.getInstance().stop();//停止定位
63 | //或者
64 | //locationClient.stopLocation();
65 | }
66 |
67 | @Override
68 | public void onClick(View v) {
69 |
70 | switch (v.getId()) {
71 | case R.id.tvStart:
72 | List permissionItems = new ArrayList<>();
73 | permissionItems.add(new PermissionItem(Manifest.permission.ACCESS_FINE_LOCATION, "地理位置", R.drawable.permission_ic_location));
74 | permissionItems.add(new PermissionItem(Manifest.permission.READ_EXTERNAL_STORAGE, "存储权限", R.drawable.permission_ic_storage));
75 | permissionItems.add(new PermissionItem(Manifest.permission.READ_PHONE_STATE, "手机状态", R.drawable.permission_ic_phone));
76 | HiPermission.create(this)
77 | .permissions(permissionItems)
78 | .checkMutiPermission(new PermissionCallback() {
79 | @Override
80 | public void onClose() {
81 | }
82 |
83 | @Override
84 | public void onFinish() {
85 | //每2秒定位一次
86 | HiLocation.with(MainActivity.this).callBack(MainActivity.this).interval(2000).start();
87 | }
88 |
89 | @Override
90 | public void onDeny(String permission, int position) {
91 |
92 | }
93 |
94 | @Override
95 | public void onGuarantee(String permission, int position) {
96 |
97 | }
98 | });
99 | break;
100 | case R.id.tvStop:
101 | //停止定位
102 | HiLocation.with(MainActivity.this).stop();
103 | break;
104 | }
105 |
106 |
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/hilocation/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 | android {
5 | compileSdkVersion rootProject.ext.compileVersion
6 | buildToolsVersion rootProject.ext.buildToolsVersion
7 |
8 | defaultConfig {
9 | minSdkVersion rootProject.ext.minSdk
10 | targetSdkVersion rootProject.ext.targetSdk
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
33 | //项目主页
34 | def siteUrl = 'https://github.com/yewei02538/HiLocation'
35 | //项目的git地址
36 | def gitUrl = 'https://github.com/yewei02538/HiLocation.git'
37 | //发布到JCenter上的项目名字
38 | def libName = "HiLocation"
39 |
40 | //发布到组织名称名字,必须填写
41 | group = "me.weyye"
42 | // 版本号,下次更新是只需要更改版本号即可
43 | version = rootProject.ext.version_name
44 | //上面配置后上传至JCenter后的编译路径是这样的: compile 'me.songning.CircleView:library:1.0.0'
45 |
46 | //生成源文件
47 | task sourcesJar(type: Jar) {
48 | from android.sourceSets.main.java.srcDirs
49 | classifier = 'sources'
50 | }
51 |
52 | //生成Javadoc文档
53 | task javadoc(type: Javadoc) {
54 | source = android.sourceSets.main.java.srcDirs
55 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
56 | }
57 |
58 | //文档打包成jar
59 | task javadocJar(type: Jar, dependsOn: javadoc) {
60 | classifier = 'javadoc'
61 | from javadoc.destinationDir
62 | }
63 |
64 | //拷贝javadoc文件
65 | task copyDoc(type: Copy) {
66 | from "${buildDir}/docs/"
67 | into "docs"
68 | }
69 |
70 | //上传到JCenter所需要的源码文件
71 | artifacts {
72 | archives javadocJar
73 | archives sourcesJar
74 | }
75 |
76 | // 配置maven库,生成POM.xml文件
77 | install {
78 | repositories.mavenInstaller {
79 | // This generates POM.xml with proper parameters
80 | pom {
81 | project {
82 | packaging 'aar'
83 | //项目描述,随意填
84 | name '一个简单易用的漂亮的权限申请库'
85 | url siteUrl
86 | licenses {
87 | license {
88 | //开源协议
89 | name 'The Apache Software License, Version 2.0'
90 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
91 | }
92 | }
93 | developers {
94 | developer {
95 | //开发者的个人信息
96 | id 'yewei02538'
97 | name 'yewei02538'
98 | email 'hiweyye@gmail.com'
99 | }
100 | }
101 | scm {
102 | connection gitUrl
103 | developerConnection gitUrl
104 | url siteUrl
105 | }
106 | }
107 | }
108 | }
109 | }
110 |
111 | //上传到JCenter
112 | Properties properties = new Properties()
113 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
114 |
115 | bintray {
116 | user = properties.getProperty("bintray.user") //读取 local.properties 文件里面的 bintray.user
117 | key = properties.getProperty("bintray.apikey") //读取 local.properties 文件里面的 bintray.apikey
118 | configurations = ['archives']
119 | pkg {
120 | //这里的repo值必须要和你创建Maven仓库的时候的名字一样
121 | repo = "maven"
122 | //发布到JCenter上的项目名字
123 | name = libName
124 | //项目描述
125 | desc = '一个简单易用的漂亮的权限申请库'
126 | websiteUrl = siteUrl
127 | vcsUrl = gitUrl
128 | licenses = ["Apache-2.0"]
129 | publish = true
130 | }
131 | }
132 |
133 | javadoc {
134 | options{
135 | //如果你的项目里面有中文注释的话,必须将格式设置为UTF-8,不然会出现乱码
136 | encoding "UTF-8"
137 | charSet 'UTF-8'
138 | author true
139 | version true
140 | links "http://docs.oracle.com/javase/7/docs/api"
141 | }
142 | }
--------------------------------------------------------------------------------
/hilocation/src/main/java/me/weyye/hilocation/HiLocation.java:
--------------------------------------------------------------------------------
1 | package me.weyye.hilocation;
2 |
3 | import android.content.Context;
4 |
5 | import com.amap.api.location.AMapLocation;
6 | import com.amap.api.location.AMapLocationClient;
7 | import com.amap.api.location.AMapLocationClientOption;
8 | import com.amap.api.location.AMapLocationListener;
9 |
10 | import java.lang.ref.WeakReference;
11 |
12 | /**
13 | * Created by Administrator on 2017/5/26 0026.
14 | */
15 |
16 | public class HiLocation {
17 |
18 | private AMapLocationClientOption mLocationOption;
19 | private AMapLocationClient mLocationClient;
20 | private Context mContext;
21 | private boolean mIsOnceLocation;
22 | private HiLocationListener mHiLocationListener;
23 |
24 | private static HiLocation mInstance;
25 |
26 | public HiLocation(Context context) {
27 | mContext = context;
28 | mLocationClient = new AMapLocationClient(mContext);
29 | //初始化定位参数
30 | mLocationOption = new AMapLocationClientOption();
31 | mLocationOption.setInterval(1000);
32 | //设置定位监听
33 | mLocationClient.setLocationOption(mLocationOption);
34 | //设置定位模式为高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式
35 | mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
36 | }
37 |
38 | public static HiLocation with(Context context) {
39 | if (mInstance == null) {
40 | synchronized (HiLocation.class) {
41 | if (mInstance == null) {
42 | mInstance = new HiLocation(context);
43 | }
44 | }
45 | }
46 | return mInstance;
47 | }
48 |
49 | public static HiLocation getInstance() {
50 | if (mInstance == null) {
51 | throw new IllegalArgumentException("请先调用HiLocation.with(Context context)");
52 | }
53 | return mInstance;
54 | }
55 |
56 | public HiLocation mode(AMapLocationClientOption.AMapLocationMode mode) {
57 | mLocationOption.setLocationMode(mode);
58 | return this;
59 | }
60 |
61 | public HiLocation timeOut(long time) {
62 | mLocationOption.setHttpTimeOut(time);
63 | return this;
64 | }
65 |
66 | public HiLocation interval(long time) {
67 | if (time == -1) {
68 | mIsOnceLocation = true;
69 | } else {
70 |
71 | mIsOnceLocation = false;
72 | mLocationOption.setInterval(time);
73 | }
74 |
75 | return this;
76 | }
77 |
78 | public HiLocation start() {
79 | mLocationClient.startLocation();
80 | return this;
81 | }
82 |
83 | public HiLocation stop() {
84 | mLocationClient.stopLocation();
85 | return this;
86 | }
87 |
88 | public HiLocation onDestory() {
89 | mHiLocationListener.onDestory();
90 | mLocationClient.stopLocation();
91 | mLocationClient.onDestroy();
92 | return this;
93 | }
94 |
95 | public HiLocation callBack(LocationListener listener) {
96 |
97 | if (mHiLocationListener != null)//之前注册过 ,移除掉
98 | mLocationClient.unRegisterLocationListener(mHiLocationListener);
99 | mHiLocationListener = new HiLocationListener(this, listener);
100 | mLocationClient.setLocationListener(mHiLocationListener);
101 | return this;
102 | }
103 |
104 | public HiLocation onceLocation() {
105 | mIsOnceLocation = true;
106 | return this;
107 | }
108 |
109 |
110 | static class HiLocationListener implements AMapLocationListener {
111 |
112 | private LocationListener mListener;
113 | private WeakReference mHiLocationWeakReference;
114 | private HiLocation mHiLocation;
115 |
116 | public HiLocationListener(HiLocation hiLocation, LocationListener listener) {
117 | mHiLocation = hiLocation;
118 | mListener = listener;
119 | }
120 |
121 | @Override
122 | public void onLocationChanged(AMapLocation aMapLocation) {
123 | int errorCode = aMapLocation.getErrorCode();
124 | if (errorCode == 0) {
125 | //只定位一次,停止定位
126 | if (mHiLocation.mIsOnceLocation)
127 | mHiLocation.stop();
128 | //定位成功
129 | if (mListener != null)
130 | mListener.onSuccess(aMapLocation);
131 | } else if (errorCode != 8) {
132 | //因为修改了jar改了包名,所以第一次定位会抛出异常,出现code为8的错误,所以直接过滤
133 | if (mListener != null)
134 | mListener.onError(mHiLocation.mLocationClient, aMapLocation);
135 | }
136 | }
137 |
138 | public void onDestory() {
139 | mHiLocation = null;
140 | }
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | Android
39 |
40 |
41 | Android > Lint > Correctness
42 |
43 |
44 | Android > Lint > Internationalization
45 |
46 |
47 | Android > Lint > Performance
48 |
49 |
50 | Assignment issuesJava
51 |
52 |
53 | Class structureJava
54 |
55 |
56 | Code style issuesJava
57 |
58 |
59 | Control flow issuesJava
60 |
61 |
62 | CorrectnessLintAndroid
63 |
64 |
65 | Encapsulation issuesJava
66 |
67 |
68 | General
69 |
70 |
71 | Google Cloud Endpoints
72 |
73 |
74 | HTML
75 |
76 |
77 | Java
78 |
79 |
80 | LintAndroid
81 |
82 |
83 | Probable bugsJava
84 |
85 |
86 | RELAX NG
87 |
88 |
89 | Serialization issuesJava
90 |
91 |
92 | TestNGJava
93 |
94 |
95 | Threading issuesJava
96 |
97 |
98 |
99 |
100 | Android
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 | 1.8
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------