Add jsr305 as a dependency to AAR.

jsr305 is necessary dependency for Nullable annotations.

Also adds a flag to release_aar.py to specify the build directory
manually. This makes it easier to test the script without full
recompilation.

Bug: webrtc:8881
Change-Id: Ib4b8cd4592ced9c92ca2810928bcbb6173d2164e
Reviewed-on: https://webrtc-review.googlesource.com/65081
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22671}
diff --git a/examples/aarproject/app/build.gradle b/examples/aarproject/app/build.gradle
index dde0707..ca9793f 100644
--- a/examples/aarproject/app/build.gradle
+++ b/examples/aarproject/app/build.gradle
@@ -46,6 +46,7 @@
     implementation fileTree(dir: 'libs', include: ['*.jar'])
     implementation fileTree(dir: '../../androidapp/third_party/autobanh/lib', include: ['autobanh.jar'])
     implementation 'com.android.support:appcompat-v7:26.1.0'
+    implementation 'com.google.code.findbugs:jsr305:3.0.2'
     implementation 'org.webrtc:google-webrtc:1.0.+'
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'com.android.support.test:runner:1.0.1'
diff --git a/tools_webrtc/android/release_aar.py b/tools_webrtc/android/release_aar.py
index 1e91bf9..bb22b11 100644
--- a/tools_webrtc/android/release_aar.py
+++ b/tools_webrtc/android/release_aar.py
@@ -69,6 +69,9 @@
       help='Skips running the tests.')
   parser.add_argument('--publish', action='store_true', default=False,
       help='Automatically publishes the library if the tests pass.')
+  parser.add_argument('--build-dir', default=None,
+      help='Temporary directory to store the build files. If not specified, '
+           'a new directory will be created.')
   parser.add_argument('--verbose', action='store_true', default=False,
       help='Debug logging.')
   return parser.parse_args()
@@ -227,7 +230,7 @@
     raise Exception('Failed to delete version. Response: %s' % response)
 
 
-def ReleaseAar(use_goma, skip_tests, publish):
+def ReleaseAar(use_goma, skip_tests, publish, build_dir):
   version = '1.0.' + _GetCommitPos()
   commit = _GetCommitHash()
   logging.info('Releasing AAR version %s with hash %s', version, commit)
@@ -238,18 +241,21 @@
     raise Exception('Environment variables BINTRAY_USER and BINTRAY_API_KEY '
                     'must be defined.')
 
-  tmp_dir = tempfile.mkdtemp()
+  # If build directory is not specified, create a temporary directory.
+  use_tmp_dir = not build_dir
+  if use_tmp_dir:
+    build_dir = tempfile.mkdtemp()
 
   try:
     base_name = ARTIFACT_ID + '-' + version
-    aar_file = os.path.join(tmp_dir, base_name + '.aar')
-    third_party_licenses_file = os.path.join(tmp_dir, 'LICENSE.md')
-    pom_file = os.path.join(tmp_dir, base_name + '.pom')
+    aar_file = os.path.join(build_dir, base_name + '.aar')
+    third_party_licenses_file = os.path.join(build_dir, 'LICENSE.md')
+    pom_file = os.path.join(build_dir, base_name + '.pom')
 
-    logging.info('Building at %s', tmp_dir)
+    logging.info('Building at %s', build_dir)
     BuildAar(ARCHS, aar_file,
              use_goma=use_goma,
-             ext_build_dir=os.path.join(tmp_dir, 'aar-build'))
+             ext_build_dir=os.path.join(build_dir, 'aar-build'))
     _GeneratePom(pom_file, version, commit)
 
     _UploadFile(user, api_key, aar_file, version, base_name + '.aar')
@@ -257,7 +263,7 @@
                 'THIRD_PARTY_LICENSES.md')
     _UploadFile(user, api_key, pom_file, version, base_name + '.pom')
 
-    tests_pass = skip_tests or _TestAAR(tmp_dir, user, api_key, version)
+    tests_pass = skip_tests or _TestAAR(build_dir, user, api_key, version)
     if not tests_pass:
       logging.info('Discarding library.')
       _PublishAAR(user, api_key, version, {'discard': True})
@@ -271,13 +277,14 @@
       logging.info('Note: The library has not not been published automatically.'
                    ' Please do so manually if desired.')
   finally:
-    shutil.rmtree(tmp_dir, True)
+    if use_tmp_dir:
+      shutil.rmtree(build_dir, True)
 
 
 def main():
   args = _ParseArgs()
   logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
-  ReleaseAar(args.use_goma, args.skip_tests, args.publish)
+  ReleaseAar(args.use_goma, args.skip_tests, args.publish, args.build_dir)
 
 
 if __name__ == '__main__':
diff --git a/tools_webrtc/android/templates/pom.jinja b/tools_webrtc/android/templates/pom.jinja
index 90ca51ca..0236772 100644
--- a/tools_webrtc/android/templates/pom.jinja
+++ b/tools_webrtc/android/templates/pom.jinja
@@ -15,4 +15,12 @@
     <project.build.commitid>{{ commit }}</project.build.commitid>
   </properties>
 
+  <dependencies>
+    <dependency>
+      <groupId>com.google.code.findbugs</groupId>
+      <artifactId>jsr305</artifactId>
+      <version>3.+</version>
+    </dependency>
+  </dependencies>
+
 </project>